jenkins_api_client 0.11.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.travis.yml +11 -5
- data/CHANGELOG.md +91 -12
- data/CONTRIBUTORS.md +13 -0
- data/Gemfile +5 -4
- data/README.md +136 -64
- data/Rakefile +63 -1
- data/Vagrantfile +85 -0
- data/config/login.yml.example +4 -0
- data/jenkins_api_client.gemspec +33 -22
- data/jenkins_api_client_class_diagram.png +0 -0
- data/lib/jenkins_api_client/build_queue.rb +40 -4
- data/lib/jenkins_api_client/cli/job.rb +4 -11
- data/lib/jenkins_api_client/client.rb +339 -83
- data/lib/jenkins_api_client/exceptions.rb +165 -21
- data/lib/jenkins_api_client/job.rb +388 -120
- data/lib/jenkins_api_client/node.rb +19 -9
- data/lib/jenkins_api_client/system.rb +32 -4
- data/lib/jenkins_api_client/user.rb +119 -0
- data/lib/jenkins_api_client/version.rb +1 -1
- data/lib/jenkins_api_client/view.rb +24 -5
- data/lib/jenkins_api_client.rb +1 -0
- data/spec/func_tests/client_spec.rb +9 -15
- data/spec/func_tests/job_spec.rb +199 -51
- data/spec/func_tests/node_spec.rb +29 -12
- data/spec/func_tests/spec_helper.rb +1 -7
- data/spec/func_tests/system_spec.rb +25 -6
- data/spec/func_tests/user_spec.rb +49 -0
- data/spec/func_tests/view_spec.rb +101 -34
- data/spec/unit_tests/build_queue_spec.rb +5 -1
- data/spec/unit_tests/client_spec.rb +27 -49
- data/spec/unit_tests/job_spec.rb +58 -6
- data/spec/unit_tests/node_spec.rb +5 -8
- data/spec/unit_tests/spec_helper.rb +1 -0
- data/spec/unit_tests/system_spec.rb +16 -3
- data/spec/unit_tests/user_spec.rb +126 -0
- data/spec/unit_tests/view_spec.rb +12 -8
- data/travis/jenkins_config.xml +63 -0
- data/travis/jenkins_config_with_crumb.xml +67 -0
- data/travis/setup.sh +22 -0
- data/travis/setup_crumb.sh +11 -0
- data/travis/spec.yml +14 -0
- data/travis/user_config.xml +29 -0
- metadata +183 -139
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -2,23 +2,29 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 2.0.0
|
4
4
|
- 1.9.3
|
5
|
-
- 1.9.2
|
6
5
|
- jruby-18mode
|
7
6
|
- jruby-19mode
|
8
7
|
- rbx-18mode
|
9
8
|
- rbx-19mode
|
10
|
-
- ruby-head
|
11
|
-
- jruby-head
|
12
9
|
- 1.8.7
|
13
10
|
- ree
|
14
11
|
matrix:
|
15
12
|
allow_failures:
|
16
13
|
- rvm: jruby-18mode
|
17
14
|
- rvm: jruby-19mode
|
18
|
-
- rvm:
|
15
|
+
- rvm: rbx-18mode
|
16
|
+
- rvm: rbx-19mode
|
19
17
|
- rvm: ree
|
20
|
-
|
18
|
+
before_install:
|
19
|
+
- travis/setup.sh
|
20
|
+
|
21
|
+
script:
|
22
|
+
- bundle exec rake unit_tests
|
23
|
+
- bundle exec rake func_tests
|
24
|
+
- travis/setup_crumb.sh
|
25
|
+
- bundle exec rake func_tests
|
21
26
|
notifications:
|
27
|
+
webhooks: https://www.buildheroes.com/api/projects/588c9dffdc8f0deff4d89d87bf370e8dba8a8a95/builds
|
22
28
|
email: false
|
23
29
|
irc:
|
24
30
|
on_success: change
|
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,77 @@ CHANGELOG
|
|
4
4
|
upcoming
|
5
5
|
--------
|
6
6
|
|
7
|
+
v0.14.0 [07-AUG-2013]
|
8
|
+
----------------------
|
9
|
+
* Fixed a bug where a space was missing in the exec_cli method argument list.
|
10
|
+
Credit: @missedone
|
11
|
+
* Refactored create/update jobs by introducing create_or_update methods.
|
12
|
+
Credit: @riywo
|
13
|
+
* Enhancement to crumb processing - auto detect the change of crumb setting and
|
14
|
+
do proper exception handling. Credit: dougforpress
|
15
|
+
* Added a `User` class which will handle jenkins users related functions.
|
16
|
+
Credit: dougforpres
|
17
|
+
* Added a method `Job#poll` which will poll for SCM changes programatically.
|
18
|
+
* Added a shortcut method `System#restart!` for force restart.
|
19
|
+
|
20
|
+
v0.13.0 [09-JUL-2013]
|
21
|
+
----------------------
|
22
|
+
* Jenkins XSS disable option is now supported. No inputs are required - the
|
23
|
+
jenkins_api_client will automatically detech whether to use the crumbs or not
|
24
|
+
when making the POST requests.
|
25
|
+
* Support for logging is added. Logs can be redirected to a log file and the
|
26
|
+
log level can be customized. This implementation uses the `Logger` class so
|
27
|
+
it follows the nice format in logging messages.
|
28
|
+
* The job `build` method will now optionally return the build number. This
|
29
|
+
option should be used with care as the build method will wait till the
|
30
|
+
jenkins job is placed on an executor from the build queue. By default the
|
31
|
+
build number will NOT be returned. nil will be returned if the build number
|
32
|
+
is not available. Also a Timeout error will be raised if the job waits in the
|
33
|
+
queue for longer than the 'timeout' parameter. This timeout parameter can be
|
34
|
+
set during the client initialization.
|
35
|
+
* Improved documentation
|
36
|
+
* Support for enabling/disabling jobs. Credit: @dieterdemeyer
|
37
|
+
* Added functionality for copying jobs. Credit: @dieterdemeyer
|
38
|
+
* Added functionality for wiping out the workspace of a job.
|
39
|
+
Credit: @dieterdemeyer
|
40
|
+
* Added functionality for listing jenkins users. Credit: @dieterdemeyer
|
41
|
+
* Fixed a bug where the exceptions where not thrown when using the
|
42
|
+
`get_console_output` method.
|
43
|
+
* Fixed a bug where the jenkins_path attribute was ignored when the server_url
|
44
|
+
input argument is given. Credit: @woodbusy
|
45
|
+
* support public/private key pair authentication for Jenkins CLI.
|
46
|
+
Credit: @missedone
|
47
|
+
|
48
|
+
|
49
|
+
v0.12.1 [25-JUN-2013]
|
50
|
+
----------------------
|
51
|
+
* Fixed a bug where the SSL support was not working properly with Ruby
|
52
|
+
1.8.7/JRuby 1.6. Credit: @brettporter (For more info:
|
53
|
+
https://github.com/arangamani/jenkins_api_client/pull/85)
|
54
|
+
|
55
|
+
v0.12.0 [18-JUN-2013]
|
56
|
+
----------------------
|
57
|
+
* Authentication is now optional as not all Jenkins instances have
|
58
|
+
authentication enabled by default. Credit: @dougforpres
|
59
|
+
* Ability to retrieve build details so that more than just (`lamp color`) is
|
60
|
+
available. Credit: @dougforpres
|
61
|
+
* Ability to retrieve build test-results for those builds that have them.
|
62
|
+
Credit: @dougforpres
|
63
|
+
* Option to follow any 301/302 responses. This allows POST to build to follow
|
64
|
+
the redirect and end up with a 200 response. Credit: @dougforpres
|
65
|
+
* Minor change to the POST requests handling where jenkins instances with a
|
66
|
+
proxy returns 411 if no form data is specified. Fixed by sending an empty
|
67
|
+
hash. Credit: @dougforpres
|
68
|
+
* As of Jenkins release 1.519, the job build returns a 201 code instead of 302.
|
69
|
+
This was resulting in an exception and the exception handling is modified to
|
70
|
+
handle this condition.
|
71
|
+
* The jobs that are not built yet have a new color (`notbuilt`) in the recent
|
72
|
+
version of jenkins (> 1.517) which resulted in `invalid` status. This is fixed.
|
73
|
+
|
7
74
|
v0.11.0 [09-JUN-2013]
|
8
75
|
----------------------
|
9
|
-
* A new input argument `server_url` is supported which accepts the jenkins URL
|
76
|
+
* A new input argument `server_url` is supported which accepts the jenkins URL
|
77
|
+
instead of IP address and Port. Credit: @dieterdemeyer
|
10
78
|
* When renaming the job, preserve the job history. Credit: @rubytester
|
11
79
|
* Various exception handling improvements. Credit: @drnic
|
12
80
|
|
@@ -20,17 +88,21 @@ v0.10.0 [24-APR-2013]
|
|
20
88
|
|
21
89
|
v0.9.1 [01-APR-2013]
|
22
90
|
---------------------
|
23
|
-
* Removed the dependency of ActiveSupport and Builder as they were not being
|
91
|
+
* Removed the dependency of ActiveSupport and Builder as they were not being
|
92
|
+
used.
|
24
93
|
|
25
94
|
v0.9.0 [10-MAR-2013]
|
26
95
|
---------------------
|
27
96
|
* Added capability to send email notification to existing jobs
|
28
97
|
* Removed warnings from client.rb
|
29
98
|
* Refactored and improved exception handling
|
30
|
-
* A bug is fixed in client which allows only the valid params as options.
|
31
|
-
|
99
|
+
* A bug is fixed in client which allows only the valid params as options.
|
100
|
+
Credit: @Niarfe
|
101
|
+
* Added a timeout parameter for waiting for jenkins to become ready.
|
102
|
+
Credit: @Niarfe
|
32
103
|
* Added function to reload jenkins. Credit: @missedone
|
33
|
-
* Fixed a bug where jenkins_path was missing in get_config and post_config.
|
104
|
+
* Fixed a bug where jenkins_path was missing in get_config and post_config.
|
105
|
+
Credit: @cylol
|
34
106
|
* Added capability to obtain jenkins version and other useful information
|
35
107
|
* Added new tests for various cases, and other code improvements
|
36
108
|
|
@@ -42,7 +114,8 @@ v0.8.0 [14-FEB-2013]
|
|
42
114
|
---------------------
|
43
115
|
* Added capability to send timer trigger while creating a job
|
44
116
|
* Added rename feature for jobs
|
45
|
-
* Added support for sending skype notification in job creation and on existing
|
117
|
+
* Added support for sending skype notification in job creation and on existing
|
118
|
+
jobs
|
46
119
|
* Added support for sending Jenkins root URL configuration. Credit: @kevinhcross
|
47
120
|
* Added `delete_all!` methods for Job, View, and Node.
|
48
121
|
* `get_eta` in BuildQueue will return "N/A" if the ETA is not given by Jenkins
|
@@ -52,7 +125,8 @@ v0.8.0 [14-FEB-2013]
|
|
52
125
|
|
53
126
|
v0.7.3 [05-FEB-2013]
|
54
127
|
---------------------
|
55
|
-
* Fixed #27 with a bug in create_view including extra character in the end of
|
128
|
+
* Fixed #27 with a bug in create_view including extra character in the end of
|
129
|
+
the name
|
56
130
|
|
57
131
|
v0.7.2 [02-FEB-2013]
|
58
132
|
---------------------
|
@@ -76,24 +150,29 @@ v0.7.0 [27-JAN-2013]
|
|
76
150
|
|
77
151
|
v0.6.2 [13-JAN-2013]
|
78
152
|
---------------------
|
79
|
-
* Fixed a bug where running job previously aborted was not recognized by the
|
153
|
+
* Fixed a bug where running job previously aborted was not recognized by the
|
154
|
+
color
|
80
155
|
|
81
156
|
v0.6.1 [13-JAN-2013]
|
82
157
|
---------------------
|
83
|
-
* Fixed a bug where the last few lines of console output was missed in the CLI
|
158
|
+
* Fixed a bug where the last few lines of console output was missed in the CLI
|
159
|
+
when using the `jenkinscli job console` command.
|
84
160
|
|
85
161
|
v0.6.0 [12-JAN-2013]
|
86
162
|
---------------------
|
87
163
|
* Added functionality to get progressive console output from Jenkins.
|
88
|
-
* Added CLI command `console` for printing progressive console output on
|
89
|
-
|
164
|
+
* Added CLI command `console` for printing progressive console output on
|
165
|
+
terminal.
|
166
|
+
* Fixed a bug with `get_current_build_number` not returning the recent running
|
167
|
+
build number.
|
90
168
|
|
91
169
|
v0.5.0 [22-DEC-2012]
|
92
170
|
---------------------
|
93
171
|
* Added functionality to create jobs with params.
|
94
172
|
* Added View class and added methods accessing List Views of Jenkins server.
|
95
173
|
* Added functionality to abort a running job.
|
96
|
-
* Deprecated `list_running` of Job class. `list_by_status('running')` is
|
174
|
+
* Deprecated `list_running` of Job class. `list_by_status('running')` is
|
175
|
+
suggested.
|
97
176
|
|
98
177
|
v0.4.0 [07-DEC-2012]
|
99
178
|
---------------------
|
data/CONTRIBUTORS.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Thank you very much to all who contributed to this project.
|
2
|
+
|
3
|
+
* [Niarfe](https://github.com/Niarfe)
|
4
|
+
* [dieterdemeyer](https://github.com/dieterdemeyer)
|
5
|
+
* [kevinhcross](https://github.com/kevinhcross)
|
6
|
+
* [drnic](https://github.com/drnic)
|
7
|
+
* [woodbusy](https://github.com/woodbusy)
|
8
|
+
* [missedone](https://github.com/missedone)
|
9
|
+
* [cylol](https://github.com/cylol)
|
10
|
+
* [madisp](https://github.com/madisp)
|
11
|
+
* [rubytester](https://github.com/rubytester)
|
12
|
+
* [dougforpres](https://github.com/dougforpres)
|
13
|
+
* [brettporter](https://github.com/brettporter)
|
data/Gemfile
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
source "
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gem "nokogiri"
|
3
|
+
gem "nokogiri", "~> 1.5.0"
|
4
4
|
gem "thor", ">= 0.16.0"
|
5
5
|
gem "json", ">= 0"
|
6
6
|
gem "terminal-table", ">= 1.4.0"
|
7
|
-
gem "mixlib-shellout", "
|
7
|
+
gem "mixlib-shellout", ">= 1.1.0"
|
8
8
|
|
9
9
|
group :development do
|
10
10
|
gem "bundler", ">= 1.0"
|
11
11
|
gem "jeweler", ">= 1.6.4"
|
12
|
+
gem "rspec", "~> 2.13.0"
|
12
13
|
gem "simplecov"
|
13
|
-
gem "
|
14
|
+
gem "yard"
|
14
15
|
end
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Copyright © 2012-2013, Kannan Manickam [![endorse](http://api.coderwall.com
|
|
9
9
|
|
10
10
|
Client libraries for communicating with a Jenkins CI server and programatically managing jobs.
|
11
11
|
|
12
|
-
IRC Channel: ##jenkins-api-client
|
12
|
+
IRC Channel: ##jenkins-api-client (on freenode)
|
13
13
|
|
14
14
|
Mailing list: jenkins_api_client@googlegroups.com
|
15
15
|
|
@@ -17,20 +17,18 @@ Google Group: https://groups.google.com/group/jenkins_api_client
|
|
17
17
|
|
18
18
|
OVERVIEW:
|
19
19
|
---------
|
20
|
-
This project is a simple API client for interacting with Jenkins Continuous
|
21
|
-
Jenkins provides three kinds of remote access API.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
This project is a simple API client for interacting with Jenkins Continuous
|
21
|
+
Integration server. Jenkins provides three kinds of remote access API.
|
22
|
+
1. XML API, 2. JSON API, and 3. Python API. This project aims at consuming the
|
23
|
+
JSON API and provides some useful functions for controlling jobs on the Jenkins
|
24
|
+
programatically. Even though Jenkins provides an awesome UI for controlling
|
25
|
+
jobs, it would be nice and helpful to have a programmable interface so we can
|
26
|
+
dynamically and automatically manage jobs and other artifacts.
|
26
27
|
|
27
28
|
DETAILS:
|
28
29
|
--------
|
29
|
-
This projects currently only provides functionality for the
|
30
|
-
|
31
|
-
work and the functionality mainly focussed on my usage and I believe others might find it useful
|
32
|
-
too. I would love to add more features to it and I will continue working on improving existing
|
33
|
-
features and add more interfaces such as nodes, views, build queue, etc,.
|
30
|
+
This projects currently only provides functionality for the
|
31
|
+
<tt>jobs, node, view, system, and build queue</tt> interfaces.
|
34
32
|
|
35
33
|
USAGE:
|
36
34
|
------
|
@@ -44,30 +42,45 @@ Include this gem in your code as a require statement.
|
|
44
42
|
|
45
43
|
### Using with IRB
|
46
44
|
|
47
|
-
If you want to just play with it and not actually want to write a script, you
|
48
|
-
irb launcher script which is available in
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
location
|
45
|
+
If you want to just play with it and not actually want to write a script, you
|
46
|
+
can just use the irb launcher script which is available in
|
47
|
+
<tt>scripts/login_with_irb.rb</tt>. But make sure that you have your credentials
|
48
|
+
available in the correct location. By default the script assumes that you have
|
49
|
+
your credentials file in <tt>~/.jenkins_api_client/login.yml</tt>. If you don't
|
50
|
+
prefer this location and would like to use a different location, just modify
|
51
|
+
that script to point to the location where the credentials file exists.
|
53
52
|
|
54
53
|
ruby scripts/login_with_irb.rb
|
55
54
|
|
56
|
-
You will see the that it entered IRB session and you can play with the API
|
57
|
-
<tt>@client</tt> object that it has returned.
|
55
|
+
You will see the that it entered IRB session and you can play with the API
|
56
|
+
client with the <tt>@client</tt> object that it has returned.
|
58
57
|
|
59
58
|
### Authentication
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
parameter
|
60
|
+
Supplying credentials to the client is optional, as not all Jenkins instances
|
61
|
+
require authentication. This project supports two types of password-based
|
62
|
+
authentication. You can just you the plain password by using <tt>password</tt>
|
63
|
+
parameter. If you don't prefer leaving plain passwords in the credentials file,
|
64
|
+
you can encode your password in base64 format and use <tt>password_base64</tt>
|
65
|
+
parameter to specify the password either in the arguments or in the credentials
|
66
|
+
file. To use the client without credentials, just leave out the
|
67
|
+
<tt>username</tt> and <tt>password</tt> parameters. The <tt>password</tt>
|
68
|
+
parameter is only required if <tt>username</tt> is specified.
|
69
|
+
|
70
|
+
### Cross-site Scripting (XSS) and Crumb Support
|
71
|
+
|
72
|
+
Support for Jenkins crumbs has been added. These allow an application to
|
73
|
+
use the Jenkins API POST methods without requiring the 'Prevent Cross Site
|
74
|
+
Request Forgery exploits' to be disabled. The API will check in with the
|
75
|
+
Jenkins server to determine whether crumbs are enabled or not, and use them
|
76
|
+
if appropriate.
|
65
77
|
|
66
78
|
### Basic Usage
|
67
79
|
|
68
|
-
As discussed earlier, you can either specify all the credentials and server
|
69
|
-
parameters to the Client or have a credentials file and just
|
70
|
-
The following call just passes the
|
80
|
+
As discussed earlier, you can either specify all the credentials and server
|
81
|
+
information as parameters to the Client or have a credentials file and just
|
82
|
+
parse the yaml file and pass it in. The following call just passes the
|
83
|
+
information as parameters
|
71
84
|
|
72
85
|
```ruby
|
73
86
|
@client = JenkinsApi::Client.new(:server_ip => '0.0.0.0',
|
@@ -76,8 +89,8 @@ The following call just passes the information as parameters
|
|
76
89
|
puts @client.job.list("^Testjob")
|
77
90
|
```
|
78
91
|
|
79
|
-
The following example passes the YAML file contents. An example yaml file is
|
80
|
-
<tt>config/login.yml.example</tt>.
|
92
|
+
The following example passes the YAML file contents. An example yaml file is
|
93
|
+
located in <tt>config/login.yml.example</tt>.
|
81
94
|
|
82
95
|
```ruby
|
83
96
|
@client = JenkinsApi::Client.new(YAML.Load_file(File.expand_path(
|
@@ -88,8 +101,8 @@ puts @client.job.list_all
|
|
88
101
|
|
89
102
|
### Chaining and Building Jobs
|
90
103
|
|
91
|
-
Sometimes we want certain jobs to be added as downstream projects and run them
|
92
|
-
The following example will explain how this could be done.
|
104
|
+
Sometimes we want certain jobs to be added as downstream projects and run them
|
105
|
+
sequencially. The following example will explain how this could be done.
|
93
106
|
|
94
107
|
```ruby
|
95
108
|
require 'jenkins_api_client'
|
@@ -117,28 +130,35 @@ code = @client.job.build(initial_jobs[0])
|
|
117
130
|
raise "Could not build the job specified" unless code == 302
|
118
131
|
```
|
119
132
|
|
120
|
-
In the above example, you might have noticed that the chain method returns an
|
121
|
-
single job. There is a reason behind it. In simple chain,
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
133
|
+
In the above example, you might have noticed that the chain method returns an
|
134
|
+
array instead of a single job. There is a reason behind it. In simple chain,
|
135
|
+
such as the one in the example above, all jobs specified are chained one by
|
136
|
+
one. But in some cases they might not be dependent on the previous jobs and we
|
137
|
+
might want to run some jobs parallelly. We just have to specify that as a
|
138
|
+
parameter.
|
139
|
+
|
140
|
+
For example: <tt>parallel = 3</tt> in the parameter list to the <tt>chain</tt>
|
141
|
+
method will take the first three jobs and chain them with the next three jobs
|
142
|
+
and so forth till it reaches the end of the list.
|
143
|
+
|
144
|
+
There is another filter option you can specify for the method to take only
|
145
|
+
jobs that are in a particular state. In case if we want to build only jobs
|
146
|
+
that are failed or unstable, we can achieve that by passing in the states in
|
147
|
+
the third parameter. In the example above, we wanted build all jobs. If we just
|
148
|
+
want to build failed and unstable jobs, just pass
|
149
|
+
<tt>["failure", "unstable"]</tt>. Also if you pass in an empty array, it will
|
150
|
+
assume that you want to consider all jobs and no filtering will be performed.
|
151
|
+
|
152
|
+
There is another parameter called <tt>threshold</tt> you can specify for the
|
153
|
+
chaining and this is used to decide whether to move forward with the next job
|
154
|
+
in the chain or not. A <tt>success</tt> will move to the next job only if the
|
155
|
+
current build succeeds, <tt>failure</tt> will move to the next job even if the
|
156
|
+
build fails, and <tt>unstable</tt> will move to the job even if the build is
|
157
|
+
unstable.
|
158
|
+
|
159
|
+
The following call to the <tt>chain</tt> method will consider only failed and
|
160
|
+
unstable jobs, chain then with 'failure' as the threshold, and also chain three
|
161
|
+
jobs in parallel.
|
142
162
|
|
143
163
|
```ruby
|
144
164
|
initial_jobs = @client.job.chain(jobs, 'failure', ["failure", "unstable"], 3)
|
@@ -152,17 +172,35 @@ end
|
|
152
172
|
### Running Jenkins CLI
|
153
173
|
To running [Jenkins CLI](https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI)
|
154
174
|
|
175
|
+
* authentication with username/password (deprecated)
|
176
|
+
|
155
177
|
```ruby
|
156
|
-
@client = JenkinsApi::Client.new(:server_ip => '
|
178
|
+
@client = JenkinsApi::Client.new(:server_ip => '127.0.0.1',
|
157
179
|
:username => 'somename', :password => 'secret password')
|
158
180
|
# The following call will return the version of Jenkins instance
|
159
181
|
puts @client.exec_cli("version")
|
160
182
|
```
|
161
183
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
184
|
+
* authentication with public/private key file
|
185
|
+
remember to upload the public key to
|
186
|
+
http://<Server IP>:<Server Port>/user/<Username>/configure
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
@client = JenkinsApi::Client.new(:server_ip => '127.0.0.1',
|
190
|
+
:identity_file => '~/.ssh/id_rsa')
|
191
|
+
# The following call will return the version of Jenkins instance
|
192
|
+
puts @client.exec_cli("version")
|
193
|
+
```
|
194
|
+
|
195
|
+
Before you run the CLI, please make sure the following requirements are
|
196
|
+
fulfilled:
|
197
|
+
* JRE/JDK 6 (or above) is installed, and 'java' is on the $PATH environment
|
198
|
+
variable
|
199
|
+
* The ```jenkins_api_client/java_deps/jenkins-cli.jar``` is required as the
|
200
|
+
client to run the CLI. You can retrieve the available commands via accessing
|
201
|
+
the URL: ```http://<server>:<port>/cli```
|
202
|
+
* (Optional) required if you run the Groovy Script through CLI, make sure
|
203
|
+
the *user* have the privilige to run script
|
166
204
|
|
167
205
|
### Using with command line
|
168
206
|
Command line interface is supported only from version 0.2.0.
|
@@ -171,12 +209,46 @@ See help using <tt>jenkinscli help</tt>
|
|
171
209
|
There are three ways for authentication using command line interface
|
172
210
|
1. Passing all credentials and server information using command line parameters
|
173
211
|
2. Passing the credentials file as the command line parameter
|
174
|
-
3. Having the credentials file in the default location
|
212
|
+
3. Having the credentials file in the default location
|
213
|
+
<tt>HOME/.jenkins_api_client/login.yml</tt>
|
175
214
|
|
176
215
|
### Debug
|
177
216
|
|
178
|
-
|
179
|
-
|
217
|
+
As of v0.13.0, this debug parameter is removed. Use the logger instead. See the
|
218
|
+
next section for more information about this option.
|
219
|
+
|
220
|
+
### Logger
|
221
|
+
|
222
|
+
As of v0.13.0, support for logger is introduced. Since it would be nice to have
|
223
|
+
the activities of the jenkins_api_client in a log file, this feature is
|
224
|
+
implemented using the Ruby's standard Logger class. For using this feature,
|
225
|
+
there are two new input arguments used during the initialization of Client.
|
226
|
+
|
227
|
+
1. `:log_location` - This argument specifies the location for the log file. A
|
228
|
+
good location for linux based systems would be
|
229
|
+
'/var/log/jenkins_api_client.log'. The default for this values is STDOUT.
|
230
|
+
This will print the log messages on the console itself.
|
231
|
+
2. `:log_level` - This argument specifies the level of messages to be logged.
|
232
|
+
It should be one of Logger::DEBUG (0), Logger::INFO (1), Logger::WARN (2),
|
233
|
+
Logger::ERROR (3), Logger::FATAL (4). It can be specified either using the
|
234
|
+
constants available in the Logger class or using these integers provided
|
235
|
+
here. The default for this argument is Logger::INFO (1)
|
236
|
+
|
237
|
+
If you want customization on the functionality Logger provides such as leave n
|
238
|
+
old log files, open the log file in append mode, create your own logger and
|
239
|
+
then set that in the client.
|
240
|
+
|
241
|
+
#### Examples
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
@client = JenkinsApi::Client.new(...)
|
245
|
+
# Create a logger which ages logfile once it reaches a certain size. Leave 10
|
246
|
+
# “old log files” and each file is about 1,024,000 bytes.
|
247
|
+
@client.logger = Logger.new('foo.log', 10, 1024000)
|
248
|
+
```
|
249
|
+
Please refer to [Ruby
|
250
|
+
Logger](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html)
|
251
|
+
for more information.
|
180
252
|
|
181
253
|
CONTRIBUTING:
|
182
254
|
-------------
|
@@ -195,6 +267,6 @@ Please take a look at the issues page if you want to get started.
|
|
195
267
|
FEATURE REQUEST:
|
196
268
|
----------------
|
197
269
|
|
198
|
-
If you use this gem for your project and you think it would be nice to have a
|
199
|
-
that is presently not implemented, I would love to hear that
|
200
|
-
Just open an issue in Github as a feature request.
|
270
|
+
If you use this gem for your project and you think it would be nice to have a
|
271
|
+
particular feature that is presently not implemented, I would love to hear that
|
272
|
+
and consider working on it. Just open an issue in Github as a feature request.
|
data/Rakefile
CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
require 'jenkins_api_client/version'
|
4
4
|
require 'rake'
|
5
5
|
require 'jeweler'
|
6
|
+
require 'yard'
|
6
7
|
|
7
8
|
Jeweler::Tasks.new do |gemspec|
|
8
9
|
gemspec.name = 'jenkins_api_client'
|
@@ -41,4 +42,65 @@ RSpec::Core::RakeTask.new(:test) do |spec|
|
|
41
42
|
spec.rspec_opts = ['--color', '--format documentation']
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
+
YARD::Config.load_plugin 'thor'
|
46
|
+
YARD::Rake::YardocTask.new do |t|
|
47
|
+
t.files = ['lib/**/*.rb', 'lib/**/**/*.rb']
|
48
|
+
end
|
49
|
+
|
50
|
+
namespace :doc do
|
51
|
+
# This task requires that graphviz is installed locally. For more info:
|
52
|
+
# http://www.graphviz.org/
|
53
|
+
desc "Generates the class diagram using the yard generated dot file"
|
54
|
+
task :generate_class_diagram do
|
55
|
+
puts "Generating the dot file..."
|
56
|
+
`yard graph --file jenkins_api_client.dot`
|
57
|
+
puts "Generating class diagram from the dot file..."
|
58
|
+
`dot jenkins_api_client.dot -Tpng -o jenkins_api_client_class_diagram.png`
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Applies Google Analytics tracking script to all generated html files"
|
62
|
+
task :apply_google_analytics do
|
63
|
+
files = Dir.glob("**/*.html")
|
64
|
+
|
65
|
+
string_to_replace = "</body>"
|
66
|
+
string_to_replace_with = <<-EOF
|
67
|
+
<script type="text/javascript">
|
68
|
+
var _gaq = _gaq || [];
|
69
|
+
_gaq.push(['_setAccount', 'UA-37519629-2']);
|
70
|
+
_gaq.push(['_trackPageview']);
|
71
|
+
|
72
|
+
(function() {
|
73
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
74
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
75
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
76
|
+
})();
|
77
|
+
</script>
|
78
|
+
</body>
|
79
|
+
EOF
|
80
|
+
|
81
|
+
files.each do |html_file|
|
82
|
+
puts "Processing file: #{html_file}"
|
83
|
+
contents = ""
|
84
|
+
# Read the file contents
|
85
|
+
file = File.open(html_file)
|
86
|
+
file.each { |line| contents << line }
|
87
|
+
file.close
|
88
|
+
|
89
|
+
# If the file already has google analytics tracking info, skip it.
|
90
|
+
if contents.include?(string_to_replace_with)
|
91
|
+
puts "Skipped..."
|
92
|
+
next
|
93
|
+
end
|
94
|
+
|
95
|
+
# Apply google analytics tracking info to the html file
|
96
|
+
contents.gsub!(string_to_replace, string_to_replace_with)
|
97
|
+
|
98
|
+
# Write the contents with the google analytics info to the file
|
99
|
+
file = File.open(html_file, "w")
|
100
|
+
file.write(contents)
|
101
|
+
file.close
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
task :default => [:unit_tests]
|