jenkins_api_client 0.5.0 → 0.6.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/.travis.yml +2 -1
- data/{CHANGELOG.rdoc → CHANGELOG.md} +30 -13
- data/lib/jenkins_api_client/cli/job.rb +24 -0
- data/lib/jenkins_api_client/client.rb +9 -5
- data/lib/jenkins_api_client/job.rb +36 -2
- data/lib/jenkins_api_client/version.rb +1 -1
- data/spec/job_spec.rb +10 -10
- metadata +4 -5
data/.travis.yml
CHANGED
@@ -6,7 +6,8 @@ before_install:
|
|
6
6
|
- sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
|
7
7
|
- sudo apt-get update -qq
|
8
8
|
- sudo apt-get install -qq jenkins
|
9
|
-
- echo `service jenkins status`
|
9
|
+
- echo `sudo service jenkins status`
|
10
|
+
- cat /var/log/jenkins/jenkins.log
|
10
11
|
- echo `curl 10.0.2.15:8080`
|
11
12
|
- echo `curl 10.0.2.15`
|
12
13
|
- echo `curl localhost:8080`
|
@@ -1,41 +1,58 @@
|
|
1
|
-
|
1
|
+
CHANGELOG
|
2
|
+
=========
|
2
3
|
|
3
|
-
|
4
|
+
v0.6.0
|
5
|
+
------
|
6
|
+
* Added functionality to get progressive console output from Jenkins.
|
7
|
+
* Added CLI command `console` for printing progressive console output on terminal.
|
8
|
+
* Fixed a bug with `get_current_build_number` not returning the recent running build number.
|
9
|
+
|
10
|
+
v0.5.0 [22-DEC-2012]
|
11
|
+
---------------------
|
4
12
|
* Added functionality to create jobs with params.
|
5
13
|
* Added View class and added methods accessing List Views of Jenkins server.
|
6
14
|
* Added functionality to abort a running job.
|
7
|
-
* Deprecated list_running of Job class. list_by_status('running') is suggested.
|
15
|
+
* Deprecated `list_running` of Job class. `list_by_status('running')` is suggested.
|
8
16
|
|
9
|
-
|
17
|
+
v0.4.0 [07-DEC-2012]
|
18
|
+
---------------------
|
10
19
|
* Added some methods for handling jobs.
|
11
|
-
* The status
|
20
|
+
* The status `not run` is not returned as `not_run` from job status.
|
12
21
|
|
13
|
-
|
22
|
+
v0.3.2 [17-NOV-2012]
|
23
|
+
---------------------
|
14
24
|
* Added some new methods for Job class
|
15
25
|
|
16
|
-
|
26
|
+
v0.3.1 [11-NOV-2012]
|
27
|
+
---------------------
|
17
28
|
* Removed unnecessary debug statements
|
18
29
|
|
19
|
-
|
30
|
+
v0.3.0 [11-NOV-2012]
|
31
|
+
---------------------
|
20
32
|
* Added System class to support quietdown and restart functionality.
|
21
33
|
* Added Node class to query the node interface of Jenkins server.
|
22
34
|
* Added Command line interface for System and Node class.
|
23
35
|
* Introduced terminal tables for displaying attributes in command line.
|
24
36
|
|
25
|
-
|
37
|
+
v0.2.1 [02-NOV-2012]
|
38
|
+
---------------------
|
26
39
|
* Added command line interface for basic operations
|
27
40
|
|
28
|
-
|
41
|
+
v0.1.1 [30-OCT-2012]
|
42
|
+
---------------------
|
29
43
|
* Updated gem dependencies to work with Ruby 1.8.7
|
30
44
|
|
31
|
-
|
45
|
+
v0.1.0 [26-OCT-2012]
|
46
|
+
---------------------
|
32
47
|
* Improved performance
|
33
48
|
* Added job create feature, delete feature, chaining feature, and build feature
|
34
49
|
* Added exception handling mechanism
|
35
50
|
|
36
|
-
|
51
|
+
v0.0.2 [16-OCT-2012]
|
52
|
+
---------------------
|
37
53
|
* Added documentation
|
38
54
|
* Added some more smal features to Job class
|
39
55
|
|
40
|
-
|
56
|
+
v0.0.1 [15-OCT-2012]
|
57
|
+
---------------------
|
41
58
|
* Initial Release
|
@@ -76,6 +76,30 @@ module JenkinsApi
|
|
76
76
|
puts @client.job.delete(job)
|
77
77
|
end
|
78
78
|
|
79
|
+
desc "console JOB", "Print the progressive console output of a job"
|
80
|
+
method_option :sleep, :aliases => "-z", :desc => "Time to wait between querying the API for console output"
|
81
|
+
def console(job)
|
82
|
+
@client = Helper.setup(parent_options)
|
83
|
+
# If debug is enabled, disable it. It shouldn't interfere with console output.
|
84
|
+
debug_changed = false
|
85
|
+
if @client.debug == true
|
86
|
+
@client.debug = false
|
87
|
+
debug_changed = true
|
88
|
+
end
|
89
|
+
|
90
|
+
# Print progressive console output
|
91
|
+
response = @client.job.get_console_output(job)
|
92
|
+
puts response['output'] unless response['more']
|
93
|
+
while response['more']
|
94
|
+
size = response['size']
|
95
|
+
puts response['output'] unless response['output'].chomp.empty?
|
96
|
+
sleep options[:sleep].to_i if options[:sleep]
|
97
|
+
response = @client.job.get_console_output(job, 0, size)
|
98
|
+
end
|
99
|
+
# Change the debug back if we changed it now
|
100
|
+
@client.toggle_debug if debug_changed
|
101
|
+
end
|
102
|
+
|
79
103
|
desc "restrict JOB", "Restricts a job to a specific node"
|
80
104
|
method_option :node, :aliases => "-n", :desc => "Node to be restricted to"
|
81
105
|
def restrict(job)
|
@@ -112,16 +112,20 @@ module JenkinsApi
|
|
112
112
|
#
|
113
113
|
# @param [String] url_prefix
|
114
114
|
#
|
115
|
-
def api_get_request(url_prefix, tree = nil)
|
115
|
+
def api_get_request(url_prefix, tree = nil, url_suffix ="/api/json")
|
116
116
|
http = Net::HTTP.start(@server_ip, @server_port)
|
117
|
-
request = Net::HTTP::Get.new("#{url_prefix}
|
118
|
-
puts "[INFO] GET #{url_prefix}
|
119
|
-
request = Net::HTTP::Get.new("#{url_prefix}
|
117
|
+
request = Net::HTTP::Get.new("#{url_prefix}#{url_suffix}")
|
118
|
+
puts "[INFO] GET #{url_prefix}#{url_suffix}" if @debug
|
119
|
+
request = Net::HTTP::Get.new("#{url_prefix}#{url_suffix}?#{tree}") if tree
|
120
120
|
request.basic_auth @username, @password
|
121
121
|
response = http.request(request)
|
122
122
|
case response.code.to_i
|
123
123
|
when 200
|
124
|
-
|
124
|
+
if url_suffix =~ /json/
|
125
|
+
return JSON.parse(response.body)
|
126
|
+
else
|
127
|
+
return response
|
128
|
+
end
|
125
129
|
when 401
|
126
130
|
raise Exceptions::UnautherizedException.new("HTTP Code: #{response.code.to_s}, Response Body: #{response.body}")
|
127
131
|
when 404
|
@@ -215,6 +215,41 @@ module JenkinsApi
|
|
215
215
|
create(job_name, job_xml)
|
216
216
|
end
|
217
217
|
|
218
|
+
# Get progressive console output from Jenkins server for a job
|
219
|
+
#
|
220
|
+
# @param [String] job_name Name of the Jenkins job
|
221
|
+
# @param [Number] build_number Specific build number to obtain the console output from. Default is the recent build
|
222
|
+
# @param [Number] start start offset to get only a portion of the text
|
223
|
+
# @param [String] mode Mode of text output. 'text' or 'html'
|
224
|
+
#
|
225
|
+
# @return [Hash] response
|
226
|
+
# * +output+ Console output of the job
|
227
|
+
# * +size+ Size of the text. This can be used as 'start' for the next call to get progressive output
|
228
|
+
# * +more+ More data available for the job. 'true' if available and nil otherwise
|
229
|
+
#
|
230
|
+
def get_console_output(job_name, build_number = 0, start = 0, mode = 'text')
|
231
|
+
build_number = get_current_build_number(job_name) if build_number == 0
|
232
|
+
if build_number == 0
|
233
|
+
puts "No builds for this job '#{job_name}' yet."
|
234
|
+
return nil
|
235
|
+
end
|
236
|
+
if mode == 'text'
|
237
|
+
mode = 'Text'
|
238
|
+
elsif mode == 'html'
|
239
|
+
mode = 'Html'
|
240
|
+
else
|
241
|
+
raise "Mode should either be 'text' or 'html'. You gave: #{mode}"
|
242
|
+
end
|
243
|
+
api_response = @client.api_get_request("/job/#{job_name}/#{build_number}/logText/progressive#{mode}?start=#{start}", nil, nil)
|
244
|
+
#puts "Response: #{api_response.header['x-more-data']}"
|
245
|
+
response = {}
|
246
|
+
response['output'] = api_response.body
|
247
|
+
response['size'] = api_response.header['x-text-size']
|
248
|
+
response['more'] = api_response.header['x-more-data']
|
249
|
+
|
250
|
+
response
|
251
|
+
end
|
252
|
+
|
218
253
|
# List all jobs on the Jenkins CI server
|
219
254
|
#
|
220
255
|
def list_all
|
@@ -348,8 +383,7 @@ module JenkinsApi
|
|
348
383
|
# @param [String] job_name
|
349
384
|
#
|
350
385
|
def get_current_build_number(job_name)
|
351
|
-
|
352
|
-
builds.length > 0 ? builds.first["number"] : nil
|
386
|
+
@client.api_get_request("/job/#{job_name}")['nextBuildNumber'] - 1
|
353
387
|
end
|
354
388
|
|
355
389
|
# This functions lists all jobs that are currently running on the Jenkins CI server
|
data/spec/job_spec.rb
CHANGED
@@ -117,16 +117,16 @@ describe JenkinsApi::Client::Job do
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
120
|
+
it "Should be able to abort a recent build of a running job" do
|
121
|
+
@client.job.get_current_build_status(@job_name).should_not == "running"
|
122
|
+
@client.job.build(@job_name)
|
123
|
+
sleep 20
|
124
|
+
@client.job.get_current_build_status(@job_name).should == "running"
|
125
|
+
sleep 20
|
126
|
+
@client.job.stop_build(@job_name).should.to_i == 302
|
127
|
+
sleep 20
|
128
|
+
@client.job.get_current_build_status(@job_name).should == "aborted"
|
129
|
+
end
|
130
130
|
|
131
131
|
it "Should be able to restrict a job to a node" do
|
132
132
|
@client.job.restrict_to_node(@job_name, 'master').to_i.should == 200
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -181,12 +181,11 @@ email:
|
|
181
181
|
executables:
|
182
182
|
- jenkinscli
|
183
183
|
extensions: []
|
184
|
-
extra_rdoc_files:
|
185
|
-
- CHANGELOG.rdoc
|
184
|
+
extra_rdoc_files: []
|
186
185
|
files:
|
187
186
|
- .gitignore
|
188
187
|
- .travis.yml
|
189
|
-
- CHANGELOG.
|
188
|
+
- CHANGELOG.md
|
190
189
|
- Gemfile
|
191
190
|
- LICENCE
|
192
191
|
- README.md
|