jenkins2-api 1.0.11 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0dc51dd8cb6002895b38bd52dcf06d5f03906fcd
4
- data.tar.gz: 3ed37d6dac2519080c51c159efedc94c6f453280
2
+ SHA256:
3
+ metadata.gz: b8f8387235bc79d14b363e9112d548612e6de47619d30206a5613435dc8c7854
4
+ data.tar.gz: 0f6312936b46c1f9d1cfbb17adb43f81e2aa0ec01727a25388927aae3c901f01
5
5
  SHA512:
6
- metadata.gz: dca04af0bc21825a78a59c2d30ae1d07fc164bb7ef47fd8ca11d9c74c0df35d8d5e4a5b74a2f8b22ff7c9c80914af6e69148ab3088eea4a5d4bd0371d73d37ba
7
- data.tar.gz: c5dcdd1e9c09beebef6a1ae5d1c82f972569d3fd71d2ae85481087ab5e3c8dfcf7499a662b1b410462008fb4b14aac49380a4831171ecc98b2aa8eae68e38fd4
6
+ metadata.gz: 30ec4147422b79b321f57e2ba4df7fda87ffc07c037b582435258b6d4ee67416002081e1345218fead43cda6e4715a3fd56d89a18fe457d6b2c018f89e4848db
7
+ data.tar.gz: adf0e7b3c6dbd226749ef7bc50dea960b2863164b179d86edfeed10ff83ccd158e6d3a825d49943780f70fe2540116b1b2fff4c2ba588495052bf2d1ad1aa1dc
data/README.md CHANGED
@@ -123,3 +123,39 @@ failed_tests.each do |failed|
123
123
  puts " [✘] #{failed['name']} on #{failed['classname']}"
124
124
  end
125
125
  ```
126
+
127
+ #### List and Install plugins
128
+
129
+ ```
130
+ p client.configuration.plugin_list
131
+
132
+ client.configuration.plugin_install(
133
+ 'Blue Ocean Pipeline Editor', # Plugin name
134
+ 'blueocean-pipeline-editor' # Plugin ID
135
+ )
136
+
137
+ # Safe restart our jenkins master when all plugins are installed.
138
+ client.configuration.safe_restart
139
+ ```
140
+
141
+ From CLI:
142
+
143
+ ```
144
+ jenkins2api plugin list
145
+ jenkins2api plugin install 'Pipeline: Stage View Plugin' 'pipeline-stage-view'
146
+ jenkins2api system safe-restart
147
+ ```
148
+
149
+ #### Trigger a build
150
+
151
+ ```
152
+ client.job.build('test-project', { GIT_BRANCH: 'experiment' })
153
+ client.job.build('test-project-clone')
154
+ ```
155
+
156
+ From CLI
157
+
158
+ ```
159
+ jenkins2api job build test-project-clone
160
+ jenkins2api job build test-project --params=GIT_BRANCH:experiment GIT_REPO:customrepo
161
+ ```
@@ -34,6 +34,18 @@ module Jenkins2API
34
34
  'node <command>',
35
35
  'Node related commands'
36
36
  )
37
+ register(
38
+ Jenkins2API::Command::Plugin,
39
+ 'plugin',
40
+ 'plugin <command>',
41
+ 'Plugins related commands'
42
+ )
43
+ register(
44
+ Jenkins2API::Command::System,
45
+ 'system',
46
+ 'system <command>',
47
+ 'System related commands'
48
+ )
37
49
  end
38
50
  end
39
51
  end
@@ -64,7 +64,7 @@ module Jenkins2API
64
64
  # ==== Params:
65
65
  # +method+:: +:post+ or +:get+
66
66
  # +path+:: Path to the Jenkins resource (e.g.: +/job/my-job/+)
67
- # +response_type+:: +:json+ or +:raw+
67
+ # +response_type+:: +:json+, +:xml+ or +:raw+
68
68
  # +opts+:: sym options to pass to the endpoint. Applicable only if +:post+
69
69
  def api_request(method, path, response_type = :json, **opts)
70
70
  req = new_request(method, path, response_type, opts)
@@ -85,10 +85,11 @@ module Jenkins2API
85
85
  # Creates a new request for the API call
86
86
  # with default and required values
87
87
  def new_request(method, path, response_type, **opts)
88
- response_type = :json unless %i[json raw].include?(response_type)
88
+ response_type = :json unless %i[json raw xml].include?(response_type)
89
89
 
90
90
  parts = [@server, URI.escape(path)]
91
91
  parts << 'api/json' if response_type == :json
92
+ parts << 'api/xml' if response_type == :xml
92
93
  uri = URI(File.join(parts))
93
94
  uri.query = URI.encode_www_form(opts)
94
95
 
@@ -18,6 +18,12 @@ module Jenkins2API
18
18
 
19
19
  puts slave_name
20
20
  end
21
+
22
+ desc 'logs JOB_NAME BUILD_ID', 'Get the logs for a specific build'
23
+ # Retrieve logs for a specific job and join them by newline
24
+ def logs(name, build_id)
25
+ puts client.build.logtext_lines(name, build_id).join("\n")
26
+ end
21
27
  end
22
28
  end
23
29
  end
@@ -5,6 +5,13 @@ module Jenkins2API
5
5
  module Command
6
6
  # Contains all the commands under +job+ namespace
7
7
  class Job < Jenkins2API::ThorCommand
8
+ desc 'build JOB_NAME', 'Start a build for a specific job'
9
+ method_option :params, default: {}, type: :hash
10
+ method_option :delay, default: 0, type: :numeric
11
+ # Start a build
12
+ def build(name)
13
+ client.job.build(name, options[:params], options[:delay])
14
+ end
8
15
  end
9
16
  end
10
17
  end
@@ -0,0 +1,32 @@
1
+ require 'thor'
2
+
3
+ module Jenkins2API
4
+ # Command module wraps all the cli commands
5
+ module Command
6
+ # Contains all the commands under +plugin+ namespace
7
+ class Plugin < Jenkins2API::ThorCommand
8
+ desc 'list', 'List plugins'
9
+ # List installed plugins
10
+ def list
11
+ puts "Legend:\n I Inactive\n U Update is available\n"
12
+
13
+ client.configuration.plugin_list.each do |plugin|
14
+ flag = ' '
15
+ flag = 'I' unless plugin['active']
16
+ flag = 'U' if plugin['hasUpdate']
17
+
18
+ printf(
19
+ " [%s] %s (%s@%s)\n", flag, plugin['longName'],
20
+ plugin['shortName'], plugin['version']
21
+ )
22
+ end
23
+ end
24
+
25
+ desc 'install PLUGIN_NAME PLUGIN_ID', 'Install a specific plugin'
26
+ # Install a plugin
27
+ def install(name, id)
28
+ client.configuration.plugin_install(name, id)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ require 'thor'
2
+
3
+ module Jenkins2API
4
+ # Command module wraps all the cli commands
5
+ module Command
6
+ # Contains all the commands under +system+ namespace
7
+ class System < Jenkins2API::ThorCommand
8
+ desc 'safe-restart', 'Restart jenkins in safe mode'
9
+ # Install a plugin
10
+ def safe_restart
11
+ client.configuration.safe_restart
12
+ end
13
+ end
14
+ end
15
+ end
@@ -28,7 +28,7 @@ module Jenkins2API
28
28
  # +name+:: Name of the Job
29
29
  # +build_id+:: ID of the build
30
30
  def test_results(name, build_id)
31
- @client.api_request(:get, "/job/#{name}/#{build_id}/testReport")
31
+ @client.api_request(:get, "/job/#{name}/#{build_id}/testReport", :xml)
32
32
  end
33
33
 
34
34
  # Get +console log+ for a specific build as text
@@ -22,6 +22,15 @@ module Jenkins2API
22
22
  :"plugin.#{short}.default" => 'on'
23
23
  )
24
24
  end
25
+
26
+ # Safe-restart jenkins
27
+ def safe_restart
28
+ @client.api_request(
29
+ :post,
30
+ '/updateCenter/safeRestart',
31
+ :raw
32
+ )
33
+ end
25
34
  end
26
35
  end
27
36
  end
@@ -31,6 +31,38 @@ module Jenkins2API
31
31
  @client.api_request(:get, "/job/#{name}")['builds']
32
32
  end
33
33
 
34
+ # Get all available sub-jobs for a specific job
35
+ #
36
+ # ==== Params:
37
+ # +name+:: Name of the Job
38
+ #
39
+ # Returns with an array of jobs
40
+ def jobs(name)
41
+ @client.api_request(:get, "/job/#{name}")['jobs']
42
+ end
43
+
44
+ # Trigger a build on a specific job
45
+ #
46
+ # ==== Params:
47
+ # +name+:: Name of the job
48
+ # +parameters+:: Hash with build parameters,
49
+ # key => valule pairs
50
+ # +delay+:: Delay the build in seconds
51
+ def build(name, parameters = {}, delay = 0)
52
+ post = { parameter: [] }
53
+ parameters.each do |key, value|
54
+ post[:parameter] << { name: key, value: value }
55
+ end
56
+
57
+ @client.api_request(
58
+ :post,
59
+ "/job/#{name}/build?delay=#{delay}sec",
60
+ :raw,
61
+ json: post.to_json
62
+ )
63
+ end
64
+
65
+ # Compatibility with jenkins-api gem (for Jenkins1)
34
66
  alias get_builds builds
35
67
  end
36
68
  end
@@ -1,5 +1,5 @@
1
1
  module Jenkins2API
2
2
  # Current version to publish
3
3
  # Gemspec also uses this constant
4
- VERSION = '1.0.11'.freeze
4
+ VERSION = '1.0.17'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins2-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balazs Nadasdi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12'
31
34
  - - ">="
32
35
  - !ruby/object:Gem::Version
33
- version: '12.0'
36
+ version: 12.3.3
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '12'
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: '12.0'
46
+ version: 12.3.3
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rdoc
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +128,8 @@ files:
122
128
  - lib/commands/build.rb
123
129
  - lib/commands/job.rb
124
130
  - lib/commands/node.rb
131
+ - lib/commands/plugin.rb
132
+ - lib/commands/system.rb
125
133
  - lib/endpoints/artifact.rb
126
134
  - lib/endpoints/base_endpoint.rb
127
135
  - lib/endpoints/build.rb
@@ -142,7 +150,7 @@ homepage: https://yitsushi.github.io/jenkins2-api/
142
150
  licenses:
143
151
  - MIT
144
152
  metadata: {}
145
- post_install_message:
153
+ post_install_message:
146
154
  rdoc_options: []
147
155
  require_paths:
148
156
  - lib
@@ -150,23 +158,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
158
  requirements:
151
159
  - - ">="
152
160
  - !ruby/object:Gem::Version
153
- version: '2.1'
161
+ version: '2.0'
154
162
  required_rubygems_version: !ruby/object:Gem::Requirement
155
163
  requirements:
156
164
  - - ">="
157
165
  - !ruby/object:Gem::Version
158
166
  version: '0'
159
167
  requirements: []
160
- rubyforge_project:
161
- rubygems_version: 2.4.5.1
162
- signing_key:
168
+ rubygems_version: 3.0.1
169
+ signing_key:
163
170
  specification_version: 4
164
171
  summary: API client for Jenkins 2.
165
172
  test_files:
166
- - spec/features/build_spec.rb
173
+ - spec/spec_helper.rb
167
174
  - spec/features/client_spec.rb
168
175
  - spec/features/job_spec.rb
169
- - spec/spec_helper.rb
176
+ - spec/features/build_spec.rb
170
177
  - spec/support/fake_jenkins.rb
171
- - spec/support/fixtures/job_list.json
172
178
  - spec/support/fixtures/latest_build.json
179
+ - spec/support/fixtures/job_list.json