jenkins_api_client 0.6.2 → 0.7.0
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.
- data/.gitignore +3 -0
- data/.jenkins.yml +9 -0
- data/.travis.yml +11 -15
- data/CHANGELOG.md +15 -0
- data/Gemfile +2 -2
- data/README.md +7 -9
- data/Rakefile +27 -14
- data/lib/jenkins_api_client.rb +36 -6
- data/lib/jenkins_api_client/build_queue.rb +213 -0
- data/lib/jenkins_api_client/cli/base.rb +10 -6
- data/lib/jenkins_api_client/cli/helper.rb +13 -4
- data/lib/jenkins_api_client/cli/job.rb +6 -9
- data/lib/jenkins_api_client/cli/node.rb +6 -4
- data/lib/jenkins_api_client/cli/system.rb +2 -1
- data/lib/jenkins_api_client/client.rb +31 -25
- data/lib/jenkins_api_client/job.rb +248 -95
- data/lib/jenkins_api_client/node.rb +128 -10
- data/lib/jenkins_api_client/system.rb +4 -2
- data/lib/jenkins_api_client/version.rb +2 -2
- data/lib/jenkins_api_client/view.rb +17 -4
- data/scripts/login_with_irb.rb +4 -3
- data/spec/func_tests/client_spec.rb +90 -0
- data/spec/func_tests/job_spec.rb +348 -0
- data/spec/func_tests/node_spec.rb +174 -0
- data/spec/{spec_helper.rb → func_tests/spec_helper.rb} +2 -2
- data/spec/func_tests/system_spec.rb +55 -0
- data/spec/func_tests/view_spec.rb +53 -0
- data/spec/unit_tests/client_spec.rb +211 -0
- data/spec/unit_tests/fixtures/files/computer_sample.xml +17 -0
- data/spec/unit_tests/fixtures/files/job_sample.xml +16 -0
- data/spec/unit_tests/job_spec.rb +355 -0
- data/spec/unit_tests/node_spec.rb +192 -0
- data/spec/unit_tests/spec_helper.rb +8 -0
- data/spec/unit_tests/system_spec.rb +54 -0
- data/spec/unit_tests/view_spec.rb +127 -0
- metadata +34 -23
- data/spec/client_spec.rb +0 -52
- data/spec/job_spec.rb +0 -158
- data/spec/node_spec.rb +0 -48
- data/spec/system_spec.rb +0 -46
data/.gitignore
CHANGED
data/.jenkins.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
name: jenkins_api_client_func_tests
|
2
|
+
git: git://github.com/arangamani/jenkins_api_client.git
|
3
|
+
ref: master
|
4
|
+
script:
|
5
|
+
- bundle install
|
6
|
+
- rake unit_tests
|
7
|
+
- rake func_tests
|
8
|
+
notification_email: kannan@rightscale.com
|
9
|
+
notification_email_for_every_unstable: true
|
data/.travis.yml
CHANGED
@@ -1,24 +1,20 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
|
-
|
5
|
-
-
|
6
|
-
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
-
|
12
|
-
-
|
13
|
-
|
14
|
-
- echo `ifconfig`
|
15
|
-
- echo `hostname`
|
16
|
-
- echo `netstat -an`
|
17
|
-
script: bundle exec rspec
|
4
|
+
- 1.9.2
|
5
|
+
- jruby-18mode
|
6
|
+
- jruby-19mode
|
7
|
+
- rbx-18mode
|
8
|
+
- rbx-19mode
|
9
|
+
- ruby-head
|
10
|
+
- jruby-head
|
11
|
+
- 1.8.7
|
12
|
+
- ree
|
13
|
+
script: bundle exec rake unit_tests
|
18
14
|
notifications:
|
19
15
|
email: false
|
20
16
|
irc:
|
21
17
|
on_success: change
|
22
18
|
on_failure: always
|
23
19
|
channels:
|
24
|
-
- "irc.freenode.org##
|
20
|
+
- "irc.freenode.org##jenins-api-client"
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
upcoming
|
5
|
+
--------
|
6
|
+
|
7
|
+
v0.7.0 [27-JAN-2012]
|
8
|
+
---------------------
|
9
|
+
* Fixed a bug where the ignorecase was never used in view list
|
10
|
+
* Raise an error if the view doesnt exists while listing jobs
|
11
|
+
* Added capability to change the mode of a node
|
12
|
+
* Added support for giving node to restrict the job during creation
|
13
|
+
* Added support for notification_email option when setting up a job
|
14
|
+
* Added support for CVS provider in SCM
|
15
|
+
* Added `create_dump_slave` and `delete` methods in Node API
|
16
|
+
* Added BuildQueue class which is accessible by `@client.queue` method
|
17
|
+
* Improvements in all over the code for performance and error handling
|
18
|
+
|
4
19
|
v0.6.2 [13-JAN-2013]
|
5
20
|
---------------------
|
6
21
|
* Fixed a bug where running job previously aborted was not recognized by the color
|
data/Gemfile
CHANGED
@@ -2,14 +2,14 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
gem "nokogiri"
|
4
4
|
gem "activesupport", "~> 3.2.8"
|
5
|
-
gem "thor", "
|
5
|
+
gem "thor", ">= 0.16.0"
|
6
6
|
gem "json", ">= 0"
|
7
7
|
gem "terminal-table", ">= 1.4.0"
|
8
|
+
gem "builder", "~> 3.1.3"
|
8
9
|
|
9
10
|
group :development do
|
10
11
|
gem "bundler", ">= 1.0"
|
11
12
|
gem "jeweler", ">= 1.6.4"
|
12
|
-
gem "builder", "~> 3.1.3"
|
13
13
|
gem "simplecov"
|
14
14
|
gem "rspec"
|
15
15
|
end
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
Jenkins API Client
|
2
2
|
==================
|
3
|
+
[](https://travis-ci.org/arangamani/jenkins_api_client)
|
4
|
+
[](https://gemnasium.com/arangamani/jenkins_api_client)
|
5
|
+
[](https://codeclimate.com/github/arangamani/jenkins_api_client)
|
3
6
|
|
4
7
|
Copyright © 2012, Kannan Manickam [](http://coderwall.com/arangamani)
|
5
8
|
|
@@ -7,6 +10,8 @@ Client libraries for communicating with a Jenkins CI server and programatically
|
|
7
10
|
|
8
11
|
IRC Channel: ##jenkins-api-client
|
9
12
|
|
13
|
+
Mailing list: jenkins.api.client@librelist.com
|
14
|
+
|
10
15
|
OVERVIEW:
|
11
16
|
---------
|
12
17
|
This project is a simple API client for interacting with Jenkins Continuous Integration server.
|
@@ -18,19 +23,12 @@ automatically manage jobs and other artifacts.
|
|
18
23
|
|
19
24
|
DETAILS:
|
20
25
|
--------
|
21
|
-
This projects currently only provides functionality for the <tt>jobs, node, and system</tt> interfaces.
|
26
|
+
This projects currently only provides functionality for the <tt>jobs, node, and system</tt> interfaces.
|
22
27
|
This is still a work-in-progress project. I mainly use the functionality of this project for my autmation
|
23
28
|
work and the functionality mainly focussed on my usage and I believe others might find it useful
|
24
29
|
too. I would love to add more features to it and I will continue working on improving existing
|
25
30
|
features and add more interfaces such as nodes, views, build queue, etc,.
|
26
31
|
|
27
|
-
CODE STATUS:
|
28
|
-
------------
|
29
|
-
|
30
|
-
* Gemnasium: [](https://gemnasium.com/arangamani/jenkins_api_client)
|
31
|
-
|
32
|
-
* Code Climate: [](https://codeclimate.com/github/arangamani/jenkins_api_client)
|
33
|
-
|
34
32
|
USAGE:
|
35
33
|
------
|
36
34
|
|
@@ -69,7 +67,7 @@ parameters to the Client or have a credentials file and just parse the yaml file
|
|
69
67
|
The following call just passes the information as parameters
|
70
68
|
|
71
69
|
```ruby
|
72
|
-
@client = JenkinsApi::Client.new(:server_ip => '0.0.0.0',
|
70
|
+
@client = JenkinsApi::Client.new(:server_ip => '0.0.0.0',
|
73
71
|
:username => 'somename', :password => 'secret password')
|
74
72
|
# The following call will return all jobs matching 'Testjob'
|
75
73
|
puts @client.job.list("^Testjob")
|
data/Rakefile
CHANGED
@@ -1,24 +1,37 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'jenkins_api_client/version'
|
3
4
|
require 'rake'
|
4
5
|
require 'jeweler'
|
5
6
|
|
6
7
|
Jeweler::Tasks.new do |gemspec|
|
7
|
-
gemspec.name
|
8
|
-
gemspec.version
|
9
|
-
gemspec.platform
|
10
|
-
gemspec.date
|
11
|
-
gemspec.
|
12
|
-
gemspec.executables
|
13
|
-
gemspec.files
|
8
|
+
gemspec.name = 'jenkins_api_client'
|
9
|
+
gemspec.version = JenkinsApi::Client::VERSION
|
10
|
+
gemspec.platform = Gem::Platform::RUBY
|
11
|
+
gemspec.date = Time.now.utc.strftime("%Y-%m-%d")
|
12
|
+
gemspec.require_paths = ["lib"]
|
13
|
+
gemspec.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
14
|
+
gemspec.files = `git ls-files`.split("\n")
|
14
15
|
gemspec.extra_rdoc_files = ['CHANGELOG.rdoc', 'LICENSE', 'README.rdoc']
|
15
|
-
gemspec.authors
|
16
|
-
gemspec.email
|
17
|
-
gemspec.homepage
|
18
|
-
gemspec.summary
|
19
|
-
gemspec.description
|
16
|
+
gemspec.authors = [ 'Kannan Manickam' ]
|
17
|
+
gemspec.email = [ 'arangamani.kannan@gmail.com' ]
|
18
|
+
gemspec.homepage = 'https://github.com/arangamani/jenkins_api_client'
|
19
|
+
gemspec.summary = 'Jenkins JSON API Client'
|
20
|
+
gemspec.description = %{
|
20
21
|
This is a simple and easy-to-use Jenkins Api client with features focused on
|
21
22
|
automating Job configuration programaticaly and so forth}
|
22
23
|
gemspec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
23
24
|
gemspec.rubygems_version = '1.8.17'
|
24
25
|
end
|
26
|
+
|
27
|
+
require 'rspec/core'
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(:unit_tests) do |spec|
|
30
|
+
spec.pattern = FileList['spec/unit_tests/*_spec.rb']
|
31
|
+
spec.rspec_opts = ['--color', '--format documentation']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:func_tests) do |spec|
|
35
|
+
spec.pattern = FileList['spec/func_tests/*_spec.rb']
|
36
|
+
spec.rspec_opts = ['--color', '--format documentation']
|
37
|
+
end
|
data/lib/jenkins_api_client.rb
CHANGED
@@ -1,6 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Kannan Manickam <arangamani.kannan@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'jenkins_api_client/version'
|
24
|
+
require 'jenkins_api_client/exceptions'
|
25
|
+
require 'jenkins_api_client/client'
|
26
|
+
require 'jenkins_api_client/job'
|
27
|
+
require 'jenkins_api_client/node'
|
28
|
+
require 'jenkins_api_client/system'
|
29
|
+
require 'jenkins_api_client/view'
|
30
|
+
require 'jenkins_api_client/build_queue'
|
31
|
+
|
32
|
+
require 'jenkins_api_client/cli/helper'
|
33
|
+
require 'jenkins_api_client/cli/base'
|
34
|
+
require 'jenkins_api_client/cli/job'
|
35
|
+
require 'jenkins_api_client/cli/node'
|
36
|
+
require 'jenkins_api_client/cli/system'
|
@@ -0,0 +1,213 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 Kannan Manickam <arangamani.kannan@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
module JenkinsApi
|
24
|
+
class Client
|
25
|
+
class BuildQueue
|
26
|
+
|
27
|
+
# Initializes a new BuildQueue object.
|
28
|
+
#
|
29
|
+
# @param [Object] client a reference to Client
|
30
|
+
#
|
31
|
+
def initialize(client)
|
32
|
+
@client = client
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a string representation of BuildQueue class.
|
36
|
+
#
|
37
|
+
def to_s
|
38
|
+
"#<JenkinsApi::Client::BuildQueue>"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Gives the number of jobs currently in the build queue
|
42
|
+
#
|
43
|
+
def size
|
44
|
+
response_json = @client.api_get_request("/queue")
|
45
|
+
response_json["items"].size
|
46
|
+
end
|
47
|
+
|
48
|
+
# Lists all tasks currently in the build queue
|
49
|
+
#
|
50
|
+
def list
|
51
|
+
response_json = @client.api_get_request("/queue")
|
52
|
+
tasks = []
|
53
|
+
response_json["items"].each do |item|
|
54
|
+
tasks << item["task"]["name"]
|
55
|
+
end
|
56
|
+
tasks
|
57
|
+
end
|
58
|
+
|
59
|
+
# Gets the time number of seconds the task is in the queue
|
60
|
+
#
|
61
|
+
# @param [String] task_name Name of the task/job
|
62
|
+
#
|
63
|
+
# @return [FixNum] age in seconds
|
64
|
+
#
|
65
|
+
def get_age(task_name)
|
66
|
+
age = nil
|
67
|
+
details = get_details(task_name)
|
68
|
+
unless details.empty?
|
69
|
+
age = Time.now - Time.at(details["inQueueSince"].to_i/1000)
|
70
|
+
end
|
71
|
+
age
|
72
|
+
end
|
73
|
+
|
74
|
+
# Obtains the detail Hash from the API response
|
75
|
+
#
|
76
|
+
# @param [String] task_name Name of the task/job
|
77
|
+
#
|
78
|
+
# @return [Hash] Queue details of the specified task/job
|
79
|
+
#
|
80
|
+
def get_details(task_name)
|
81
|
+
response_json = @client.api_get_request("/queue")
|
82
|
+
details = {}
|
83
|
+
response_json["items"].each do |item|
|
84
|
+
details = item if item["task"]["name"]
|
85
|
+
end
|
86
|
+
details
|
87
|
+
end
|
88
|
+
|
89
|
+
# Obtains the causes from the build queue for the specified task
|
90
|
+
#
|
91
|
+
# @param [String] task_name
|
92
|
+
#
|
93
|
+
# @return [Array] causes for the task to be in queue
|
94
|
+
#
|
95
|
+
def get_causes(task_name)
|
96
|
+
causes = nil
|
97
|
+
details = get_details(task_name)
|
98
|
+
unless details.empty?
|
99
|
+
causes = details["actions"]["causes"]
|
100
|
+
end
|
101
|
+
causes
|
102
|
+
end
|
103
|
+
|
104
|
+
# Obtains the reason why the task is in queue
|
105
|
+
#
|
106
|
+
# @param [String] task_name name of the task
|
107
|
+
#
|
108
|
+
# @return [String] reason for being in queue, nil if no task found
|
109
|
+
#
|
110
|
+
def get_reason(task_name)
|
111
|
+
reason = nil
|
112
|
+
details = get_details(task_name)
|
113
|
+
unless details.empty?
|
114
|
+
reason = details["why"]
|
115
|
+
end
|
116
|
+
reason
|
117
|
+
end
|
118
|
+
|
119
|
+
# Obtains the ETA given by Jenkins if any
|
120
|
+
#
|
121
|
+
# @param[String] task_name name of the task
|
122
|
+
#
|
123
|
+
# @return [String] ETA for the task, nil if no task found or ETA is
|
124
|
+
# not available
|
125
|
+
#
|
126
|
+
def get_eta(task_name)
|
127
|
+
eta = nil
|
128
|
+
details = get_details(task_name)
|
129
|
+
unless details.empty?
|
130
|
+
matched = details["why"].match(/.*\(ETA:(.*)\)/)
|
131
|
+
eta = matched[1].strip unless matched.nil?
|
132
|
+
end
|
133
|
+
eta
|
134
|
+
end
|
135
|
+
|
136
|
+
# Obtains the ID of the task from the queue
|
137
|
+
#
|
138
|
+
# @param [String] task_name name of the task
|
139
|
+
#
|
140
|
+
# @return [String] ID of the task, nil of no task is found
|
141
|
+
#
|
142
|
+
def get_id(task_name)
|
143
|
+
id = nil
|
144
|
+
details = get_details(task_name)
|
145
|
+
unless details.empty?
|
146
|
+
id = details["id"]
|
147
|
+
end
|
148
|
+
id
|
149
|
+
end
|
150
|
+
|
151
|
+
# Obtains the params from the build queue
|
152
|
+
#
|
153
|
+
# @param [String] task_name name of the task
|
154
|
+
#
|
155
|
+
# @return [String] params, nil if the no task is found
|
156
|
+
#
|
157
|
+
def get_params(task_name)
|
158
|
+
params = nil
|
159
|
+
details = get_details(task_name)
|
160
|
+
unless details.empty?
|
161
|
+
params = details["params"]
|
162
|
+
end
|
163
|
+
params
|
164
|
+
end
|
165
|
+
|
166
|
+
# Obtains whether the task is buildable
|
167
|
+
#
|
168
|
+
# @param [String] task_name name of the task
|
169
|
+
#
|
170
|
+
# @return [TrueClass|FalseClass] buildable or not
|
171
|
+
#
|
172
|
+
def is_buildable?(task_name)
|
173
|
+
buildable = nil
|
174
|
+
details = get_details(task_name)
|
175
|
+
unless details.empty?
|
176
|
+
buildable = details["buildable"] == "true" ? true : false
|
177
|
+
end
|
178
|
+
buildable
|
179
|
+
end
|
180
|
+
|
181
|
+
# Obtains whether the task is blocked
|
182
|
+
#
|
183
|
+
# @param [String] task_name name of the task
|
184
|
+
#
|
185
|
+
# @return [TrueClass|FalseClass] blocked or not
|
186
|
+
#
|
187
|
+
def is_blocked?(task_name)
|
188
|
+
blocked = nil
|
189
|
+
details = get_details(task_name)
|
190
|
+
unless details.empty?
|
191
|
+
blocked = details["blocked"] == "true" ? true : false
|
192
|
+
end
|
193
|
+
blocked
|
194
|
+
end
|
195
|
+
|
196
|
+
# Obtains whether the task is stuck
|
197
|
+
#
|
198
|
+
# @param [String] task_name name of the task
|
199
|
+
#
|
200
|
+
# @return [TrueClass|FalseClass] stuck or not
|
201
|
+
#
|
202
|
+
def is_stuck?(task_name)
|
203
|
+
stuck = nil
|
204
|
+
details = get_details(task_name)
|
205
|
+
unless details.empty?
|
206
|
+
stuck = details["stuck"] == "true" ? true : false
|
207
|
+
end
|
208
|
+
stuck
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|