fastlane-plugin-update_jenkins_build 0.1.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 97103e6d6d332d6f40d11e45175040bad3be978c
4
- data.tar.gz: f168d93cff6a8217f9411255047c85cfe774ff58
2
+ SHA256:
3
+ metadata.gz: dd94a14381f6b4065878242ccd53858e717e854015c7a8b8ba74746ee8f5831b
4
+ data.tar.gz: f0fc857b6e62148a95b9be4f7a9733f8ac178f25081a88f520fe49d2ad703b19
5
5
  SHA512:
6
- metadata.gz: 50fabbb72666689bf4ed48a44ccbc74f7ae257719532a9f4185cb72e58ff66911fc1ef14b86756c5998d5ae148549fe3a063011a8d768e671240749c4b36a3c7
7
- data.tar.gz: 6331ce118460695e45fb2949b3a5c3693a6cae686b8bfb54bc89906d07a00a3c3185fc8f7aad598841687b1303fc7a2cc005f32c2a29ffa8edc0b50e6e15764b
6
+ metadata.gz: ed102c9db15db0ccbc9d42f117dccaf7dc108773ec21c316b721713e1afb6576a4a71a5b0a1a16650fb16ae87683ea6228eed55e7c6cadbf2aaacee5d6b41545
7
+ data.tar.gz: bf8a574839dc58af1aa288a23d1bf75bac42024d3dc50d390192a70f3b7547ebf91bbd47dfd3de069226a53b86fca0d0c68ef5d544b27733db8d9b84b7bf2f8b
data/README.md CHANGED
@@ -10,6 +10,15 @@ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To
10
10
  fastlane add_plugin update_jenkins_build
11
11
  ```
12
12
 
13
+ ![screenshot](screenshot.png)
14
+
15
+ ### Configure Jenkins
16
+
17
+ ⚠️ **READ ME FRIST**
18
+
19
+ Jenkins version below 2.221, you need disable CSRF Protection in Global Security Settings page or
20
+ else you must append '-Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true' into Jenkins startup argument, [Check more details](https://github.com/icyleaf/fastlane-plugin-update_jenkins_build/issues/2).
21
+
13
22
  ## About update_jenkins_build
14
23
 
15
24
  Update build's description of jenkins.
@@ -22,6 +31,7 @@ $ bundle exec fastlane action update_jenkins_build
22
31
  | Key | Description | Env Var | Default |
23
32
  +--------------+---------------------------------------------+-----------------------------------+---------+
24
33
  | description | the description of current build | UPDATE_JENKINS_BUILD_DESCRIPTION | |
34
+ | url | the url of jenkins | UPDATE_JENKINS_BUILD_URL | |
25
35
  | project | the name of project(job) | UPDATE_JENKINS_BUILD_PROJECT | |
26
36
  | build_number | the build number of project(job) | UPDATE_JENKINS_BUILD_BUILD_NUMBER | |
27
37
  | user | the user of jenkins if enabled security | UPDATE_JENKINS_BUILD_USER | |
@@ -31,7 +41,7 @@ $ bundle exec fastlane action update_jenkins_build
31
41
  +-----------------------------------+
32
42
  | update_jenkins_build Return Value |
33
43
  +-----------------------------------+
34
- | ture/false |
44
+ | [ture/false, response_body] |
35
45
  +-----------------------------------+
36
46
  ```
37
47
 
@@ -1,5 +1,6 @@
1
1
  require 'fastlane/action'
2
2
  require_relative '../helper/update_jenkins_build_helper'
3
+ require 'rubygems'
3
4
  require 'http'
4
5
  require 'uri'
5
6
 
@@ -9,49 +10,69 @@ module Fastlane
9
10
  def self.run(params)
10
11
  @user = params[:user]
11
12
  @password = params[:password]
13
+ @url = params[:url]
12
14
  @project = params[:project]
13
15
  @build_number = params[:build_number]
14
- @description = params[:description]
16
+ @description = format_description(params[:description])
15
17
 
16
18
  url = "#{base_uri}/submitDescription"
17
- res = if @user
19
+ res = if @user || @password
18
20
  HTTP.basic_auth(user: @user, pass: @password)
19
21
  .post(url, form: {description: @description})
20
22
  else
21
- HTTP.post(url, form: {description: @description})
23
+ HTTP.post(url, form: {
24
+ "description" => @description,
25
+ "Jenkins-Crumb" => "234234234234234234" # random value
26
+ })
22
27
  end
23
28
 
24
- result = res.status == 302 ? true : false
29
+ # Submit form succesed it will 302 to the build url.
30
+ result = res.code == 302 ? 'success' : "#{res.code} fail"
25
31
 
32
+ jenkins_version = Helper::UpdateJenkinsBuildHelper.jenkins_version(@url, @user, @password)
26
33
  params = {
27
34
  title: "Summary for update_jenkins_build #{UpdateJenkinsBuild::VERSION}".green,
28
35
  rows: {
29
- result: (result ? 'success' : 'fail'),
36
+ jenkins_version: jenkins_version,
37
+ result: result,
30
38
  url: "#{base_uri}/editDescription",
31
39
  auth: @user ? true : false,
32
40
  description: @description,
33
41
  }
34
42
  }
35
43
 
36
- puts ""
37
44
  puts Terminal::Table.new(params)
38
- puts ""
39
45
 
40
- result
46
+ if res.code != 302
47
+ UI.error "Detect `update_jenkins_build` ran fail."
48
+ if jenkins_version && Gem::Version.new(jenkins_version) > Gem::Version.new('2.221')
49
+ UI.error "Because Jenkins v#{jenkins_version} removed 'disable CSRF Protection' option since 2.222,"
50
+ UI.error "You need append '-Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true' into Jenkins startup argument."
51
+ UI.error "Please check https://github.com/icyleaf/fastlane-plugin-update_jenkins_build/issues/2"
52
+ else
53
+ UI.error "Please 'disable CSRF Protection' in 'Global Security Settings' page from Jenkins."
54
+ end
55
+ end
56
+
57
+ [result, res.body]
58
+ end
59
+
60
+ def self.format_description(descripion)
61
+ descripion.gsub('\n', "\n")
41
62
  end
42
63
 
43
64
  def self.base_uri
44
- uri = URI(ENV['JENKINS_URL'])
65
+ uri = URI(@url)
45
66
  uri.path = "/job/#{@project}/#{@build_number}"
46
67
  uri.to_s
47
68
  end
48
69
 
49
70
  def self.return_value
50
- "ture/false"
71
+ "[ture/false, response_body]"
51
72
  end
52
73
 
53
74
  def self.return_type
54
- :boolean
75
+ :array
55
76
  end
56
77
 
57
78
  def self.example_code
@@ -60,6 +81,7 @@ module Fastlane
60
81
  description: "AdHoc v1.0 (1.0.1)"
61
82
  )',
62
83
  'update_jenkins_build(
84
+ url: "http://127.0.0.1:8080/", # specify specific jenkins url
63
85
  project: "foobar", # specify specific project name
64
86
  build_number: 75, # specify specific build number
65
87
  description: "AdHoc v1.0 (1.0.1)",
@@ -76,6 +98,10 @@ module Fastlane
76
98
  "Update build's description of jenkins"
77
99
  end
78
100
 
101
+ def self.details
102
+ "MUST disable CSRF in Security configure"
103
+ end
104
+
79
105
  def self.available_options
80
106
  [
81
107
  FastlaneCore::ConfigItem.new(key: :description,
@@ -83,6 +109,12 @@ module Fastlane
83
109
  description: "the description of current build",
84
110
  optional: false,
85
111
  type: String),
112
+ FastlaneCore::ConfigItem.new(key: :url,
113
+ env_name: "UPDATE_JENKINS_BUILD_URL",
114
+ description: "the url of jenkins",
115
+ default_value: ENV['JENKINS_URL'],
116
+ optional: true,
117
+ type: String),
86
118
  FastlaneCore::ConfigItem.new(key: :project,
87
119
  env_name: "UPDATE_JENKINS_BUILD_PROJECT",
88
120
  description: "the name of project(job)",
@@ -5,11 +5,17 @@ module Fastlane
5
5
 
6
6
  module Helper
7
7
  class UpdateJenkinsBuildHelper
8
- # class methods that you define here become available in your action
9
- # as `Helper::UpdateJenkinsBuildHelper.your_method`
10
- #
11
- def self.show_message
12
- UI.message("Hello from the update_jenkins_build plugin helper!")
8
+
9
+ def self.jenkins_version(url, user, password)
10
+ url = "#{url}/api/json"
11
+ res = if user && password
12
+ HTTP.basic_auth(user: user, pass: password)
13
+ .get(url)
14
+ else
15
+ HTTP.get(url)
16
+ end
17
+
18
+ res.headers['X-Jenkins']
13
19
  end
14
20
  end
15
21
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module UpdateJenkinsBuild
3
- VERSION = "0.1.4"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-update_jenkins_build
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - icyleaf
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-26 00:00:00.000000000 Z
11
+ date: 2022-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -164,7 +164,7 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description:
167
+ description:
168
168
  email: icyleaf.cn@gmail.com
169
169
  executables: []
170
170
  extensions: []
@@ -180,7 +180,7 @@ homepage: https://github.com/icyleaf/fastlane-plugin-update_jenkins_build
180
180
  licenses:
181
181
  - MIT
182
182
  metadata: {}
183
- post_install_message:
183
+ post_install_message:
184
184
  rdoc_options: []
185
185
  require_paths:
186
186
  - lib
@@ -195,9 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  requirements: []
198
- rubyforge_project:
199
- rubygems_version: 2.6.12
200
- signing_key:
198
+ rubygems_version: 3.2.32
199
+ signing_key:
201
200
  specification_version: 4
202
201
  summary: Update Description of Build
203
202
  test_files: []