jenkins_api_client 1.4.5 → 1.5.2

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/jenkins_api_client.gemspec +15 -136
  3. data/lib/jenkins_api_client/version.rb +2 -2
  4. metadata +6 -180
  5. data/.gitignore +0 -41
  6. data/.jenkins.yml +0 -9
  7. data/.travis.yml +0 -15
  8. data/CHANGELOG.md +0 -391
  9. data/CONTRIBUTORS.md +0 -3
  10. data/Gemfile +0 -20
  11. data/LICENCE +0 -21
  12. data/README.md +0 -454
  13. data/Rakefile +0 -107
  14. data/Vagrantfile +0 -83
  15. data/config/login.yml.example +0 -27
  16. data/jenkins_api_client_class_diagram.png +0 -0
  17. data/scripts/login_with_irb.rb +0 -54
  18. data/scripts/login_with_pry.rb +0 -54
  19. data/spec/func_tests/client_spec.rb +0 -109
  20. data/spec/func_tests/job_spec.rb +0 -669
  21. data/spec/func_tests/node_spec.rb.pending +0 -217
  22. data/spec/func_tests/plugin_spec.rb +0 -148
  23. data/spec/func_tests/spec_helper.rb +0 -41
  24. data/spec/func_tests/system_spec.rb +0 -84
  25. data/spec/func_tests/user_spec.rb +0 -49
  26. data/spec/func_tests/view_spec.rb +0 -276
  27. data/spec/unit_tests/build_queue_spec.rb +0 -152
  28. data/spec/unit_tests/client_spec.rb +0 -471
  29. data/spec/unit_tests/fake_http_response.rb +0 -9
  30. data/spec/unit_tests/fixtures/files/available_plugins.json +0 -1
  31. data/spec/unit_tests/fixtures/files/computer_sample.xml +0 -17
  32. data/spec/unit_tests/fixtures/files/installed_plugins.json +0 -1
  33. data/spec/unit_tests/fixtures/files/job_sample.xml +0 -16
  34. data/spec/unit_tests/fixtures/files/updatable_plugins.json +0 -1
  35. data/spec/unit_tests/job_spec.rb +0 -783
  36. data/spec/unit_tests/node_spec.rb +0 -342
  37. data/spec/unit_tests/plugin_settings/colllection_spec.rb +0 -62
  38. data/spec/unit_tests/plugin_settings/hipchat_spec.rb +0 -44
  39. data/spec/unit_tests/plugin_settings/workspace_cleanup_spec.rb +0 -31
  40. data/spec/unit_tests/plugin_spec.rb +0 -165
  41. data/spec/unit_tests/spec_helper.rb +0 -19
  42. data/spec/unit_tests/system_spec.rb +0 -76
  43. data/spec/unit_tests/user_spec.rb +0 -144
  44. data/spec/unit_tests/view_spec.rb +0 -149
  45. data/travis/hudson.model.UpdateCenter.xml +0 -7
  46. data/travis/jenkins_config.xml +0 -63
  47. data/travis/jenkins_config_with_crumb.xml +0 -67
  48. data/travis/setup.sh +0 -23
  49. data/travis/setup_crumb.sh +0 -11
  50. data/travis/spec.yml +0 -14
  51. data/travis/user_config.xml +0 -29
data/README.md DELETED
@@ -1,454 +0,0 @@
1
- Jenkins API Client
2
- ==================
3
-
4
- [![Gem Version](http://img.shields.io/gem/v/jenkins_api_client.svg)][gem]
5
- [![Build Status](http://img.shields.io/travis/arangamani/jenkins_api_client.svg)][travis]
6
- [![Dependency Status](http://img.shields.io/gemnasium/arangamani/jenkins_api_client.svg)][gemnasium]
7
- [![Code Climate](http://img.shields.io/codeclimate/github/arangamani/jenkins_api_client.svg)][codeclimate]
8
-
9
- [gem]: https://rubygems.org/gems/jenkins_api_client
10
- [travis]: http://travis-ci.org/arangamani/jenkins_api_client
11
- [gemnasium]: https://gemnasium.com/arangamani/jenkins_api_client
12
- [codeclimate]: https://codeclimate.com/github/arangamani/jenkins_api_client
13
-
14
- Copyright © 2012-2013, Kannan Manickam [![endorse](http://api.coderwall.com/arangamani/endorsecount.png)](http://coderwall.com/arangamani)
15
-
16
- Client libraries for communicating with a Jenkins CI server and programatically managing jobs.
17
-
18
- IRC Channel: ##jenkins-api-client (on freenode)
19
-
20
- Mailing list: jenkins_api_client@googlegroups.com
21
-
22
- Google Group: https://groups.google.com/group/jenkins_api_client
23
-
24
- OVERVIEW:
25
- ---------
26
- This project is a simple API client for interacting with Jenkins Continuous
27
- Integration server. Jenkins provides three kinds of remote access API.
28
- 1. XML API, 2. JSON API, and 3. Python API. This project aims at consuming the
29
- JSON API and provides some useful functions for controlling jobs on the Jenkins
30
- programatically. Even though Jenkins provides an awesome UI for controlling
31
- jobs, it would be nice and helpful to have a programmable interface so we can
32
- dynamically and automatically manage jobs and other artifacts.
33
-
34
- DETAILS:
35
- --------
36
- This projects currently only provides functionality for the
37
- <tt>jobs, node, view, system, and build queue</tt> interfaces.
38
-
39
- USAGE:
40
- ------
41
-
42
- ### Installation
43
-
44
- Install jenkins_api_client by <tt>sudo gem install jenkins_api_client</tt>
45
- Include this gem in your code as a require statement.
46
-
47
- require 'jenkins_api_client'
48
-
49
- ### Using with IRB
50
-
51
- If you want to just play with it and not actually want to write a script, you
52
- can just use the irb launcher script which is available in
53
- <tt>scripts/login_with_irb.rb</tt>. But make sure that you have your credentials
54
- available in the correct location. By default the script assumes that you have
55
- your credentials file in <tt>~/.jenkins_api_client/login.yml</tt>. If you don't
56
- prefer this location and would like to use a different location, just modify
57
- that script to point to the location where the credentials file exists.
58
-
59
- ruby scripts/login_with_irb.rb
60
-
61
- You will see the that it entered IRB session and you can play with the API
62
- client with the <tt>@client</tt> object that it has returned.
63
-
64
- ### Authentication
65
-
66
- Supplying credentials to the client is optional, as not all Jenkins instances
67
- require authentication. This project supports two types of password-based
68
- authentication. You can just you the plain password by using <tt>password</tt>
69
- parameter. If you don't prefer leaving plain passwords in the credentials file,
70
- you can encode your password in base64 format and use <tt>password_base64</tt>
71
- parameter to specify the password either in the arguments or in the credentials
72
- file. To use the client without credentials, just leave out the
73
- <tt>username</tt> and <tt>password</tt> parameters. The <tt>password</tt>
74
- parameter is only required if <tt>username</tt> is specified.
75
-
76
- #### Using with Open ID
77
-
78
- It is very simple to authenticate with your Jenkins server that has Open ID
79
- authentication enabled. You will have to obtain your API token and use the API
80
- token as the password. For obtaining the API token, go to your user configuration
81
- page and click 'Show API Token'. Use this token for the `password` parameter when
82
- initializing the client.
83
-
84
- ### Cross-site Scripting (XSS) and Crumb Support
85
-
86
- Support for Jenkins crumbs has been added. These allow an application to
87
- use the Jenkins API POST methods without requiring the 'Prevent Cross Site
88
- Request Forgery exploits' to be disabled. The API will check in with the
89
- Jenkins server to determine whether crumbs are enabled or not, and use them
90
- if appropriate.
91
-
92
- ### Basic Usage
93
-
94
- As discussed earlier, you can either specify all the credentials and server
95
- information as parameters to the Client or have a credentials file and just
96
- parse the yaml file and pass it in. The following call just passes the
97
- information as parameters
98
-
99
- ```ruby
100
- @client = JenkinsApi::Client.new(:server_ip => '0.0.0.0',
101
- :username => 'somename', :password => 'secret password')
102
- # The following call will return all jobs matching 'Testjob'
103
- puts @client.job.list("^Testjob")
104
- ```
105
-
106
- The following example passes the YAML file contents. An example yaml file is
107
- located in <tt>config/login.yml.example</tt>.
108
-
109
- ```ruby
110
- @client = JenkinsApi::Client.new(YAML.load_file(File.expand_path(
111
- "~/.jenkins_api_client/login.yml", __FILE__)))
112
- # The following call lists all jobs
113
- puts @client.job.list_all
114
- ```
115
-
116
- ### Chaining and Building Jobs
117
-
118
- Sometimes we want certain jobs to be added as downstream projects and run them
119
- sequentially. The following example will explain how this could be done.
120
-
121
- ```ruby
122
- require 'jenkins_api_client'
123
-
124
- # We want to filter all jobs that start with 'test_job'
125
- # Just write a regex to match all the jobs that start with 'test_job'
126
- jobs_to_filter = "^test_job.*"
127
-
128
- # Create an instance to jenkins_api_client
129
- @client = JenkinsApi::Client.new(YAML.load_file(File.expand_path(
130
- "~/.jenkins_api_client/login.yml", __FILE__)))
131
-
132
- # Get a filtered list of jobs from the server
133
- jobs = @client.job.list(jobs_to_filter)
134
-
135
- # Chain all the jobs with 'success' as the threshold
136
- # The chain method will return the jobs that is in the head of the sequence
137
- # This method will also remove any existing chaining
138
- initial_jobs = @client.job.chain(jobs, 'success', ["all"])
139
-
140
- # Now that we have the initial job(s) we can build them
141
- # The build function returns a code from the API which should be 201 if
142
- # the build was successful, for Jenkins >= v1.519
143
- # For versions older than v1.519, the success code is 302.
144
- code = @client.job.build(initial_jobs[0])
145
- raise "Could not build the job specified" unless code == '201'
146
- ```
147
-
148
- In the above example, you might have noticed that the chain method returns an
149
- array instead of a single job. There is a reason behind it. In simple chain,
150
- such as the one in the example above, all jobs specified are chained one by
151
- one. But in some cases they might not be dependent on the previous jobs and we
152
- might want to run some jobs parallelly. We just have to specify that as a
153
- parameter.
154
-
155
- For example: <tt>parallel = 3</tt> in the parameter list to the <tt>chain</tt>
156
- method will take the first three jobs and chain them with the next three jobs
157
- and so forth till it reaches the end of the list.
158
-
159
- There is another filter option you can specify for the method to take only
160
- jobs that are in a particular state. In case if we want to build only jobs
161
- that are failed or unstable, we can achieve that by passing in the states in
162
- the third parameter. In the example above, we wanted build all jobs. If we just
163
- want to build failed and unstable jobs, just pass
164
- <tt>["failure", "unstable"]</tt>. Also if you pass in an empty array, it will
165
- assume that you want to consider all jobs and no filtering will be performed.
166
-
167
- There is another parameter called <tt>threshold</tt> you can specify for the
168
- chaining and this is used to decide whether to move forward with the next job
169
- in the chain or not. A <tt>success</tt> will move to the next job only if the
170
- current build succeeds, <tt>failure</tt> will move to the next job even if the
171
- build fails, and <tt>unstable</tt> will move to the job even if the build is
172
- unstable.
173
-
174
- The following call to the <tt>chain</tt> method will consider only failed and
175
- unstable jobs, chain then with 'failure' as the threshold, and also chain three
176
- jobs in parallel.
177
-
178
- ```ruby
179
- initial_jobs = @client.job.chain(jobs, 'failure', ["failure", "unstable"], 3)
180
- # We will receive three jobs as a result and we can build them all
181
- initial_jobs.each do |job|
182
- code = @client.job.build(job)
183
- raise "Unable to build job: #{job}" unless code == '201'
184
- end
185
- ```
186
-
187
- ### Configuring plugins
188
-
189
- Given the abundance of plugins for Jenkins, we now provide a extensible way to
190
- setup jobs and configure their plugins. Right now, the gem ships with the hipchat
191
- plugin, with more plugins to follow in the future.
192
-
193
- ```ruby
194
- hipchat_settings = JenkinsApi::Client::PluginSettings::Hipchat.new({
195
- :room => '10000',
196
- :start_notification => true,
197
- :notify_success => true,
198
- :notify_aborted => true,
199
- :notify_not_built => true,
200
- :notify_unstable => true,
201
- :notify_failure => true,
202
- :notify_back_to_normal => true,
203
- })
204
-
205
- client = JenkinsApi::Client.new(
206
- server_url: jenkins_server,
207
- username: username,
208
- password: password
209
- )
210
-
211
- # NOTE: plugins can be splatted so if you had another plugin it could be passed
212
- # to the new call below as another arg after hipchat
213
- job = JenkinsApi::Client::Job.new(client, hipchat)
214
-
215
- ```
216
-
217
- Writing your own plugins is also straightforward. Inherit from the
218
- JenkinsApi::Client::PluginSettings::Base class and override the configure method.
219
- Jenkins jobs are configured using xml so you just nee to figure out where in the
220
- configuration to hook in your plugin settings.
221
-
222
- Here is an example of a plugin written to configure a job for workspace cleanup.
223
-
224
- ```ruby
225
- module JenkinsApi
226
- class Client
227
- module PluginSettings
228
- class WorkspaceCleanup < Base
229
-
230
- # @option params [Boolean] :delete_dirs (false)
231
- # whether to also apply pattern on directories
232
- # @option params [String] :cleanup_parameters
233
- # @option params [String] :external_delete
234
- def initialize(params={})
235
- @params = params
236
- end
237
-
238
- # Create or Update a job with params given as a hash instead of the xml
239
- # This gives some flexibility for creating/updating simple jobs so the
240
- # user doesn't have to learn about handling xml.
241
- #
242
- # @param xml_doc [Nokogiri::XML::Document] xml document to be updated with
243
- # the plugin configuration
244
- #
245
- # @return [Nokogiri::XML::Document]
246
- def configure(xml_doc)
247
- xml_doc.tap do |doc|
248
- Nokogiri::XML::Builder.with(doc.at('buildWrappers')) do |build_wrappers|
249
- build_wrappers.send('hudson.plugins.ws__cleanup.PreBuildCleanup') do |x|
250
- x.deleteDirs @params.fetch(:delete_dirs) { false }
251
- x.cleanupParameter @params.fetch(:cleanup_parameter) { '' }
252
- x.externalDelete @params.fetch(:external_delete) { '' }
253
- end
254
- end
255
- end
256
- end
257
- end
258
- end
259
- end
260
- end
261
- ```
262
-
263
- Currently, the skype plugin is still configured directly on the jenkins job. This will
264
- likely be extracted into its own plugin in the near future, but we will maintain
265
- backwards compatibility until after an official deprecation period.
266
-
267
- ### Waiting for a build to start/Getting the build number
268
- Newer versions of Jenkins (starting with the 1.519 build) make it easier for
269
- an application to determine the build number for a 'build' request. (previously
270
- there would be a degree of guesswork involved). The new version actually
271
- returns information allowing the jenkins_api_client to check the build queue
272
- for the job and see if it has started yet (once it has started, the build-
273
- number is available.
274
-
275
- If you wish to take advantage of this hands-off approach, the build method
276
- supports an additional 'opts' hash that lets you specify how long you wish to
277
- wait for the build to start.
278
-
279
- #### Old Jenkins vs New Jenkins (1.519+)
280
-
281
- ##### Old (v < 1.519)
282
- The 'opts' parameter will work with older versions of Jenkins with the following
283
- caveats:
284
- * The 'cancel_on_build_start_timeout' option has no effect
285
- * The build_number is calculated by calling 'current_build_number' and adding
286
- 1 before the build is started. This might break if there are multiple
287
- entities running builds on the same job, or there are queued builds.
288
-
289
- ##### New (v >= 1.519)
290
- * All options work, and build number is accurately determined from queue
291
- info.
292
- * The build trigger success code is now 201 (Created). Previously it was 302.
293
-
294
- #### Initiating a build and returning the build_number
295
-
296
- ##### Minimum required
297
- ```ruby
298
- # Minimum options required
299
- opts = {'build_start_timeout' => 30}
300
- @client.job.build(job_name, job_params || {}, opts)
301
- ```
302
- This method will block for up to 30 seconds, while waiting for the build to
303
- start. Instead of returning an http-status code, it will return the
304
- build_number, or if the build has not started will raise 'Timeout::Error'
305
- Note: to maintain legacy compatibility, passing 'true' will set the timeout
306
- to the default timeout specified when creating the @client.
307
-
308
- ##### Auto cancel the queued-build on timeout
309
- ```ruby
310
- # Wait for up to 30 seconds, attempt to cancel queued build
311
- opts = {'build_start_timeout' => 30,
312
- 'cancel_on_build_start_timeout' => true}
313
- @client.job.build(job_name, job_params || {}, opts)
314
- ```
315
- This method will block for up to 30 seconds, while waiting for the build to
316
- start. Instead of returning an http-status code, it will return the
317
- build_number, or if the build has not started will raise 'Timeout::Error'.
318
- Prior to raising the Timeout::Error, it will attempt to cancel the queued
319
- build - thus preventing it from starting.
320
-
321
- ##### Getting some feedback while you're waiting
322
- The opts parameter supports two values that can be assigned proc objects
323
- (which will be 'call'ed). Both are optional, and will only be called if
324
- specified in opts.
325
- These are initially intended to assist with logging progress.
326
-
327
- * 'progress_proc' - called when job is initially queued, and periodically
328
- thereafter.
329
- * max_wait - the value of 'build_start_timeout'
330
- * current_wait - how long we've been waiting so far
331
- * poll_count - how many times we've polled the queue
332
- * 'completion_proc' - called just prior to return/Timeout::Error
333
- * build_number - the build number assigned (or nil if timeout)
334
- * cancelled - whether the build was cancelled (true if 'new' Jenkins
335
- and it was able to cancel the build, false otherwise)
336
-
337
- To use a class method, just specify 'instance.method(:method_name)', or
338
- use a proc or lambda
339
-
340
- ```ruby
341
- # Wait for up to 30 seconds, attempt to cancel queued build, progress
342
- opts = {'build_start_timeout' => 30,
343
- 'cancel_on_build_start_timeout' => true,
344
- 'poll_interval' => 2, # 2 is actually the default :)
345
- 'progress_proc' => lambda {|max,curr,count| ... },
346
- 'completion_proc' => lambda {|build_number,cancelled| ... }}
347
- @client.job.build(job_name, job_params || {}, opts)
348
- ```
349
- ### Running Jenkins CLI
350
- To running [Jenkins CLI](https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI)
351
-
352
- * authentication with username/password (deprecated)
353
-
354
- ```ruby
355
- @client = JenkinsApi::Client.new(:server_ip => '127.0.0.1',
356
- :username => 'somename', :password => 'secret password')
357
- # The following call will return the version of Jenkins instance
358
- puts @client.exec_cli("version")
359
- ```
360
-
361
- * authentication with public/private key file
362
- remember to upload the public key to:
363
-
364
- `http://#{Server IP}:#{Server Port}/user/#{Username}/configure`
365
-
366
- ```ruby
367
- @client = JenkinsApi::Client.new(:server_ip => '127.0.0.1',
368
- :identity_file => '~/.ssh/id_rsa')
369
- # The following call will return the version of Jenkins instance
370
- puts @client.exec_cli("version")
371
- ```
372
-
373
- Before you run the CLI, please make sure the following requirements are
374
- fulfilled:
375
- * JRE/JDK 6 (or above) is installed, and 'java' is on the $PATH environment
376
- variable
377
- * The ```jenkins_api_client/java_deps/jenkins-cli.jar``` is required as the
378
- client to run the CLI. You can retrieve the available commands via accessing
379
- the URL: ```http://<server>:<port>/cli```
380
- * (Optional) required if you run the Groovy Script through CLI, make sure
381
- the *user* have the privilige to run script
382
-
383
- ### Using with command line
384
- Command line interface is supported only from version 0.2.0.
385
- See help using <tt>jenkinscli help</tt>
386
-
387
- There are three ways for authentication using command line interface
388
- 1. Passing all credentials and server information using command line parameters
389
- 2. Passing the credentials file as the command line parameter
390
- 3. Having the credentials file in the default location
391
- <tt>HOME/.jenkins_api_client/login.yml</tt>
392
-
393
- ### Debug
394
-
395
- As of v0.13.0, this debug parameter is removed. Use the logger instead. See the
396
- next section for more information about this option.
397
-
398
- ### Logger
399
-
400
- As of v0.13.0, support for logger is introduced. Since it would be nice to have
401
- the activities of the jenkins_api_client in a log file, this feature is
402
- implemented using the Ruby's standard Logger class. For using this feature,
403
- there are two new input arguments used during the initialization of Client.
404
-
405
- 1. `:log_location` - This argument specifies the location for the log file. A
406
- good location for linux based systems would be
407
- '/var/log/jenkins_api_client.log'. The default for this values is STDOUT.
408
- This will print the log messages on the console itself.
409
- 2. `:log_level` - This argument specifies the level of messages to be logged.
410
- It should be one of Logger::DEBUG (0), Logger::INFO (1), Logger::WARN (2),
411
- Logger::ERROR (3), Logger::FATAL (4). It can be specified either using the
412
- constants available in the Logger class or using these integers provided
413
- here. The default for this argument is Logger::INFO (1)
414
-
415
- If you want customization on the functionality Logger provides such as leave n
416
- old log files, open the log file in append mode, create your own logger and
417
- then set that in the client.
418
-
419
- #### Examples
420
-
421
- ```ruby
422
- @client = JenkinsApi::Client.new(...)
423
- # Create a logger which ages logfile once it reaches a certain size. Leave 10
424
- # “old log files” and each file is about 1,024,000 bytes.
425
- @client.logger = Logger.new('foo.log', 10, 1024000)
426
- ```
427
- Please refer to [Ruby
428
- Logger](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html)
429
- for more information.
430
-
431
- CONTRIBUTING:
432
- -------------
433
-
434
- If you would like to contribute to this project, just do the following:
435
-
436
- 1. Fork the repo on Github.
437
- 2. Add your features and make commits to your forked repo.
438
- 3. Make a pull request to this repo.
439
- 4. Review will be done and changes will be requested.
440
- 5. Once changes are done or no changes are required, pull request will be merged.
441
- 6. The next release will have your changes in it.
442
-
443
- Please take a look at the issues page if you want to get started.
444
-
445
- FEATURE REQUEST:
446
- ----------------
447
-
448
- If you use this gem for your project and you think it would be nice to have a
449
- particular feature that is presently not implemented, I would love to hear that
450
- and consider working on it. Just open an issue in Github as a feature request.
451
-
452
-
453
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/arangamani/jenkins_api_client/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
454
-