jenkins_api_client 0.8.1 → 0.9.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 +1 -0
- data/CHANGELOG.md +12 -0
- data/Rakefile +5 -0
- data/lib/jenkins_api_client/build_queue.rb +9 -6
- data/lib/jenkins_api_client/cli/base.rb +0 -1
- data/lib/jenkins_api_client/cli/system.rb +6 -0
- data/lib/jenkins_api_client/client.rb +73 -35
- data/lib/jenkins_api_client/exceptions.rb +6 -2
- data/lib/jenkins_api_client/job.rb +198 -124
- data/lib/jenkins_api_client/system.rb +7 -1
- data/lib/jenkins_api_client/version.rb +2 -2
- data/lib/jenkins_api_client/view.rb +2 -0
- data/scripts/login_with_irb.rb +1 -3
- data/spec/func_tests/client_spec.rb +25 -0
- data/spec/func_tests/job_spec.rb +31 -12
- data/spec/func_tests/node_spec.rb +18 -2
- data/spec/func_tests/system_spec.rb +10 -0
- data/spec/func_tests/view_spec.rb +166 -10
- data/spec/unit_tests/build_queue_spec.rb +148 -0
- data/spec/unit_tests/client_spec.rb +59 -35
- data/spec/unit_tests/job_spec.rb +16 -0
- data/spec/unit_tests/system_spec.rb +8 -0
- metadata +4 -3
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,18 @@ CHANGELOG
|
|
4
4
|
upcoming
|
5
5
|
--------
|
6
6
|
|
7
|
+
v0.9.0 [10-MAR-2013]
|
8
|
+
---------------------
|
9
|
+
* Added capability to send email notification to existing jobs
|
10
|
+
* Removed warnings from client.rb
|
11
|
+
* Refactored and improved exception handling
|
12
|
+
* A bug is fixed in client which allows only the valid params as options. Credit: @Niarfe
|
13
|
+
* Added a timeout parameter for waiting for jenkins to become ready. Credit: @Niarfe
|
14
|
+
* Added function to reload jenkins. Credit: @missedone
|
15
|
+
* Fixed a bug where jenkins_path was missing in get_config and post_config. Credit: @cylol
|
16
|
+
* Added capability to obtain jenkins version and other useful information
|
17
|
+
* Added new tests for various cases, and other code improvements
|
18
|
+
|
7
19
|
v0.8.1 [15-FEB-2013]
|
8
20
|
---------------------
|
9
21
|
* Fixed a bug in creating view. Issue #42
|
data/Rakefile
CHANGED
@@ -35,3 +35,8 @@ RSpec::Core::RakeTask.new(:func_tests) do |spec|
|
|
35
35
|
spec.pattern = FileList['spec/func_tests/*_spec.rb']
|
36
36
|
spec.rspec_opts = ['--color', '--format documentation']
|
37
37
|
end
|
38
|
+
|
39
|
+
RSpec::Core::RakeTask.new(:test) do |spec|
|
40
|
+
spec.pattern = FileList['spec/*/*.rb']
|
41
|
+
spec.rspec_opts = ['--color', '--format documentation']
|
42
|
+
end
|
@@ -60,7 +60,7 @@ module JenkinsApi
|
|
60
60
|
#
|
61
61
|
# @param [String] task_name Name of the task/job
|
62
62
|
#
|
63
|
-
# @return [
|
63
|
+
# @return [Fixnum] age in seconds
|
64
64
|
#
|
65
65
|
def get_age(task_name)
|
66
66
|
age = nil
|
@@ -96,7 +96,10 @@ module JenkinsApi
|
|
96
96
|
causes = nil
|
97
97
|
details = get_details(task_name)
|
98
98
|
unless details.empty?
|
99
|
-
causes =
|
99
|
+
causes = []
|
100
|
+
details["actions"].each do |action|
|
101
|
+
causes << action["causes"]
|
102
|
+
end
|
100
103
|
end
|
101
104
|
causes
|
102
105
|
end
|
@@ -118,7 +121,7 @@ module JenkinsApi
|
|
118
121
|
|
119
122
|
# Obtains the ETA given by Jenkins if any
|
120
123
|
#
|
121
|
-
# @param[String] task_name name of the task
|
124
|
+
# @param [String] task_name name of the task
|
122
125
|
#
|
123
126
|
# @return [String] ETA for the task, nil if no task found and N/A for
|
124
127
|
# tasks with no ETA info.
|
@@ -179,7 +182,7 @@ module JenkinsApi
|
|
179
182
|
buildable = nil
|
180
183
|
details = get_details(task_name)
|
181
184
|
unless details.empty?
|
182
|
-
buildable = details["buildable"]
|
185
|
+
buildable = details["buildable"]
|
183
186
|
end
|
184
187
|
buildable
|
185
188
|
end
|
@@ -194,7 +197,7 @@ module JenkinsApi
|
|
194
197
|
blocked = nil
|
195
198
|
details = get_details(task_name)
|
196
199
|
unless details.empty?
|
197
|
-
blocked = details["blocked"]
|
200
|
+
blocked = details["blocked"]
|
198
201
|
end
|
199
202
|
blocked
|
200
203
|
end
|
@@ -209,7 +212,7 @@ module JenkinsApi
|
|
209
212
|
stuck = nil
|
210
213
|
details = get_details(task_name)
|
211
214
|
unless details.empty?
|
212
|
-
stuck = details["stuck"]
|
215
|
+
stuck = details["stuck"]
|
213
216
|
end
|
214
217
|
stuck
|
215
218
|
end
|
@@ -40,6 +40,12 @@ module JenkinsApi
|
|
40
40
|
@client.system.cancel_quiet_down
|
41
41
|
end
|
42
42
|
|
43
|
+
desc "reload", "Reload Jenkins server"
|
44
|
+
def reload
|
45
|
+
@client = Helper.setup(parent_options)
|
46
|
+
@client.system.reload
|
47
|
+
end
|
48
|
+
|
43
49
|
desc "restart", "Restarts the Jenkins server"
|
44
50
|
method_option :force, :type => :boolean, :aliases => "-s",
|
45
51
|
:desc => "Force restart"
|
@@ -30,9 +30,19 @@ require 'base64'
|
|
30
30
|
|
31
31
|
module JenkinsApi
|
32
32
|
class Client
|
33
|
-
attr_accessor :debug
|
33
|
+
attr_accessor :debug, :timeout
|
34
34
|
DEFAULT_SERVER_PORT = 8080
|
35
|
-
|
35
|
+
DEFAULT_TIMEOUT = 120
|
36
|
+
VALID_PARAMS = [
|
37
|
+
"server_ip",
|
38
|
+
"server_port",
|
39
|
+
"jenkins_path",
|
40
|
+
"username",
|
41
|
+
"password",
|
42
|
+
"password_base64",
|
43
|
+
"debug",
|
44
|
+
"timeout"
|
45
|
+
].freeze
|
36
46
|
|
37
47
|
# Initialize a Client object with Jenkins CI server credentials
|
38
48
|
#
|
@@ -44,13 +54,16 @@ module JenkinsApi
|
|
44
54
|
#
|
45
55
|
def initialize(args)
|
46
56
|
args.each do |key, value|
|
47
|
-
|
57
|
+
if value && VALID_PARAMS.include?(key.to_s)
|
58
|
+
instance_variable_set("@#{key}", value)
|
59
|
+
end
|
48
60
|
end if args.is_a? Hash
|
49
61
|
raise "Server IP is required to connect to Jenkins" unless @server_ip
|
50
62
|
unless @username && (@password || @password_base64)
|
51
63
|
raise "Credentials are required to connect to te Jenkins Server"
|
52
64
|
end
|
53
65
|
@server_port = DEFAULT_SERVER_PORT unless @server_port
|
66
|
+
@timeout = DEFAULT_TIMEOUT unless @timeout
|
54
67
|
@debug = false unless @debug
|
55
68
|
|
56
69
|
# Base64 decode inserts a newline character at the end. As a workaround
|
@@ -128,23 +141,7 @@ module JenkinsApi
|
|
128
141
|
puts "[INFO] GET #{to_get}" if @debug
|
129
142
|
request.basic_auth @username, @password
|
130
143
|
response = http.request(request)
|
131
|
-
|
132
|
-
case response.code.to_i
|
133
|
-
when 200
|
134
|
-
if url_suffix =~ /json/
|
135
|
-
return JSON.parse(response.body)
|
136
|
-
else
|
137
|
-
return response
|
138
|
-
end
|
139
|
-
when 401
|
140
|
-
raise Exceptions::UnautherizedException.new(msg)
|
141
|
-
when 404
|
142
|
-
raise Exceptions::NotFoundException.new(msg)
|
143
|
-
when 500
|
144
|
-
raise Exceptions::InternelServerErrorException.new(msg)
|
145
|
-
else
|
146
|
-
raise Exceptions::ApiException.new(msg)
|
147
|
-
end
|
144
|
+
handle_exception(response, "body", url_suffix =~ /json/)
|
148
145
|
end
|
149
146
|
|
150
147
|
# Sends a POST message to the Jenkins CI server with the specified URL
|
@@ -161,17 +158,7 @@ module JenkinsApi
|
|
161
158
|
request.content_type = 'application/json'
|
162
159
|
request.set_form_data(form_data) unless form_data.nil?
|
163
160
|
response = http.request(request)
|
164
|
-
|
165
|
-
case response.code.to_i
|
166
|
-
when 200, 302
|
167
|
-
return response.body
|
168
|
-
when 404
|
169
|
-
raise Exceptions::NotFoundException.new(msg)
|
170
|
-
when 500
|
171
|
-
raise Exceptions::InternelServerErrorException.new(msg)
|
172
|
-
else
|
173
|
-
raise Exceptions::ApiException.new(msg)
|
174
|
-
end
|
161
|
+
handle_exception(response)
|
175
162
|
end
|
176
163
|
|
177
164
|
# Obtains the configuration of a component from the Jenkins CI server
|
@@ -179,13 +166,13 @@ module JenkinsApi
|
|
179
166
|
# @param [String] url_prefix
|
180
167
|
#
|
181
168
|
def get_config(url_prefix)
|
182
|
-
url_prefix = URI.escape(url_prefix)
|
169
|
+
url_prefix = URI.escape("#{@jenkins_path}#{url_prefix}")
|
183
170
|
http = Net::HTTP.start(@server_ip, @server_port)
|
184
171
|
request = Net::HTTP::Get.new("#{url_prefix}/config.xml")
|
185
172
|
puts "[INFO] GET #{url_prefix}/config.xml" if @debug
|
186
173
|
request.basic_auth @username, @password
|
187
174
|
response = http.request(request)
|
188
|
-
response
|
175
|
+
handle_exception(response, "body")
|
189
176
|
end
|
190
177
|
|
191
178
|
# Posts the given xml configuration to the url given
|
@@ -194,7 +181,7 @@ module JenkinsApi
|
|
194
181
|
# @param [String] xml
|
195
182
|
#
|
196
183
|
def post_config(url_prefix, xml)
|
197
|
-
url_prefix = URI.escape(url_prefix)
|
184
|
+
url_prefix = URI.escape("#{@jenkins_path}#{url_prefix}")
|
198
185
|
http = Net::HTTP.start(@server_ip, @server_port)
|
199
186
|
request = Net::HTTP::Post.new("#{url_prefix}")
|
200
187
|
puts "[INFO] PUT #{url_prefix}" if @debug
|
@@ -202,7 +189,58 @@ module JenkinsApi
|
|
202
189
|
request.body = xml
|
203
190
|
request.content_type = 'application/xml'
|
204
191
|
response = http.request(request)
|
205
|
-
response
|
192
|
+
handle_exception(response)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Obtain the version of Jenkins CI server
|
196
|
+
#
|
197
|
+
# @return [String] Version of Jenkins
|
198
|
+
#
|
199
|
+
def get_jenkins_version
|
200
|
+
response = get_root
|
201
|
+
response["X-Jenkins"]
|
202
|
+
end
|
203
|
+
|
204
|
+
# Obtain the Hudson version of the CI server
|
205
|
+
#
|
206
|
+
# @return [String] Version of Hudson on Jenkins server
|
207
|
+
#
|
208
|
+
def get_hudson_version
|
209
|
+
response = get_root
|
210
|
+
response["X-Hudson"]
|
211
|
+
end
|
212
|
+
|
213
|
+
# Obtain the date of the Jenkins server
|
214
|
+
#
|
215
|
+
# @return [String] Server date
|
216
|
+
#
|
217
|
+
def get_server_date
|
218
|
+
response = get_root
|
219
|
+
response["Date"]
|
220
|
+
end
|
221
|
+
|
222
|
+
private
|
223
|
+
|
224
|
+
def handle_exception(response, to_send = "code", send_json = false)
|
225
|
+
msg = "HTTP Code: #{response.code}, Response Body: #{response.body}"
|
226
|
+
case response.code.to_i
|
227
|
+
when 200, 302
|
228
|
+
if to_send == "body" && send_json
|
229
|
+
return JSON.parse(response.body)
|
230
|
+
elsif to_send == "body"
|
231
|
+
return response.body
|
232
|
+
elsif to_send == "code"
|
233
|
+
return response.code
|
234
|
+
end
|
235
|
+
when 401
|
236
|
+
raise Exceptions::UnautherizedException.new
|
237
|
+
when 404
|
238
|
+
raise Exceptions::NotFoundException.new
|
239
|
+
when 500
|
240
|
+
raise Exceptions::InternelServerErrorException.new
|
241
|
+
else
|
242
|
+
raise Exceptions::ApiException.new
|
243
|
+
end
|
206
244
|
end
|
207
245
|
|
208
246
|
end
|
@@ -36,13 +36,17 @@ module JenkinsApi
|
|
36
36
|
|
37
37
|
class NotFoundException < ApiException
|
38
38
|
def initialize(message = "")
|
39
|
-
super("Requested
|
39
|
+
super("Requested component is not found on the Jenkins CI server." +
|
40
|
+
" #{message}")
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
44
|
class InternelServerErrorException < ApiException
|
44
45
|
def initialize(message = "")
|
45
|
-
super("Internel Server Error.
|
46
|
+
super("Internel Server Error. Perhaps the in-memory configuration of" +
|
47
|
+
" Jenkins is different from the disk configuration." +
|
48
|
+
" Please try to reload the configuration #{message}"
|
49
|
+
)
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
@@ -55,7 +55,7 @@ module JenkinsApi
|
|
55
55
|
# * +:block_build_when_downstream_building+ true or false
|
56
56
|
# * +:block_build_when_upstream_building+ true or false
|
57
57
|
# * +:concurrent_build+ true or false
|
58
|
-
# * +:scm_provider+ type of source control
|
58
|
+
# * +:scm_provider+ type of source control. Supported: Git, SVN, and CVS
|
59
59
|
# * +:scm_url+ remote url for scm
|
60
60
|
# * +:scm_module+ Module to download. Only for CVS.
|
61
61
|
# * +:scm_branch+ branch to use in scm. Uses master by default
|
@@ -111,7 +111,7 @@ module JenkinsApi
|
|
111
111
|
end
|
112
112
|
params[:concurrent_build] = false if params[:concurrent_build].nil?
|
113
113
|
if params[:notification_email]
|
114
|
-
if params[:
|
114
|
+
if params[:notification_email_for_every_unstable].nil?
|
115
115
|
params[:notification_email_for_every_unstable] = false
|
116
116
|
end
|
117
117
|
if params[:notification_email_send_to_individuals].nil?
|
@@ -148,82 +148,14 @@ module JenkinsApi
|
|
148
148
|
xml.properties
|
149
149
|
# SCM related stuff
|
150
150
|
if params[:scm_provider] == 'subversion'
|
151
|
-
|
152
|
-
|
153
|
-
xml.locations {
|
154
|
-
xml.send("hudson.scm.SubversionSCM_-ModuleLocation") {
|
155
|
-
xml.remote "#{params[:scm_url]}"
|
156
|
-
xml.local "."
|
157
|
-
}
|
158
|
-
}
|
159
|
-
xml.excludedRegions
|
160
|
-
xml.includedRegions
|
161
|
-
xml.excludedUsers
|
162
|
-
xml.excludedRevprop
|
163
|
-
xml.excludedCommitMessages
|
164
|
-
xml.workspaceUpdater(:class =>
|
165
|
-
"hudson.scm.subversion.UpdateUpdater")
|
166
|
-
}
|
151
|
+
# Build subversion related XML portion
|
152
|
+
scm_subversion(params, xml)
|
167
153
|
elsif params[:scm_provider] == "cvs"
|
168
|
-
|
169
|
-
|
170
|
-
xml.cvsroot "#{params[:scm_url]}"
|
171
|
-
xml.module "#{params[:scm_module]}"
|
172
|
-
if params[:scm_branch]
|
173
|
-
xml.branch "#{params[:scm_branch]}"
|
174
|
-
else
|
175
|
-
xml.branch "#{params[:scm_tag]}"
|
176
|
-
end
|
177
|
-
xml.canUseUpdate true
|
178
|
-
xml.useHeadIfNotFound(
|
179
|
-
"#{params[:scm_use_head_if_tag_not_found]}")
|
180
|
-
xml.flatten true
|
181
|
-
if params[:scm_tag]
|
182
|
-
xml.isTag true
|
183
|
-
else
|
184
|
-
xml.isTag false
|
185
|
-
end
|
186
|
-
xml.excludedRegions
|
187
|
-
}
|
154
|
+
# Build CVS related XML portion
|
155
|
+
scm_cvs(params, xml)
|
188
156
|
elsif params[:scm_provider] == "git"
|
189
|
-
|
190
|
-
|
191
|
-
xml.userRemoteConfigs {
|
192
|
-
xml.send("hudson.plugins.git.UserRemoteConfig") {
|
193
|
-
xml.name
|
194
|
-
xml.refspec
|
195
|
-
xml.url "#{params[:scm_url]}"
|
196
|
-
}
|
197
|
-
}
|
198
|
-
xml.branches {
|
199
|
-
xml.send("hudson.plugins.git.BranchSpec") {
|
200
|
-
xml.name "#{params[:scm_branch]}"
|
201
|
-
}
|
202
|
-
}
|
203
|
-
xml.disableSubmodules "false"
|
204
|
-
xml.recursiveSubmodules "false"
|
205
|
-
xml.doGenerateSubmoduleConfigurations "false"
|
206
|
-
xml.authorOrCommitter "false"
|
207
|
-
xml.clean "false"
|
208
|
-
xml.wipeOutWorkspace "false"
|
209
|
-
xml.pruneBranches "false"
|
210
|
-
xml.remotePoll "false"
|
211
|
-
xml.ignoreNotifyCommit "false"
|
212
|
-
xml.useShallowClone "false"
|
213
|
-
xml.buildChooser(:class =>
|
214
|
-
"hudson.plugins.git.util.DefaultBuildChooser")
|
215
|
-
xml.gitTool "Default"
|
216
|
-
xml.submoduleCfg(:class => "list")
|
217
|
-
xml.relativeTargetDir
|
218
|
-
xml.reference
|
219
|
-
xml.excludedRegions
|
220
|
-
xml.excludedUsers
|
221
|
-
xml.gitConfigName
|
222
|
-
xml.gitConfigEmail
|
223
|
-
xml.skipTag "false"
|
224
|
-
xml.includedRegions
|
225
|
-
xml.scmName
|
226
|
-
}
|
157
|
+
# Build Git related XML portion
|
158
|
+
scm_git(params, xml)
|
227
159
|
else
|
228
160
|
xml.scm(:class => "hudson.scm.NullSCM")
|
229
161
|
end
|
@@ -259,27 +191,11 @@ module JenkinsApi
|
|
259
191
|
}
|
260
192
|
# Adding Downstream projects
|
261
193
|
xml.publishers {
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
xml.threshold {
|
268
|
-
xml.name "#{name}"
|
269
|
-
xml.ordinal "#{ordinal}"
|
270
|
-
xml.color "#{color}"
|
271
|
-
}
|
272
|
-
}
|
273
|
-
end
|
274
|
-
if params[:notification_email]
|
275
|
-
xml.send("hudson.tasks.Mailer") {
|
276
|
-
xml.recipients "#{params[:notification_email]}"
|
277
|
-
xml.dontNotifyEveryUnstableBuild(
|
278
|
-
"#{params[:notification_email_for_every_unstable]}")
|
279
|
-
xml.sendToIndividuals(
|
280
|
-
"#{params[:notification_email_send_to_individuals]}")
|
281
|
-
}
|
282
|
-
end
|
194
|
+
# Build portion of XML that adds child projects
|
195
|
+
child_projects(params, xml) if params[:child_projects]
|
196
|
+
# Build portion of XML that adds email notification
|
197
|
+
notification_email(params, xml) if params[:notification_email]
|
198
|
+
# Build portion of XML that adds skype notification
|
283
199
|
skype_notification(params, xml) if params[:skype_targets]
|
284
200
|
}
|
285
201
|
xml.buildWrappers
|
@@ -288,6 +204,30 @@ module JenkinsApi
|
|
288
204
|
create(params[:name], builder.to_xml)
|
289
205
|
end
|
290
206
|
|
207
|
+
# Adding email notification to a job
|
208
|
+
#
|
209
|
+
# @param [Hash] params parameters to add email notification
|
210
|
+
# @option params [String] :name Name of the job
|
211
|
+
# @option params [String] :notification_email Email address to send
|
212
|
+
# @option params [TrueClass|FalseClass] :notification_email_for_every_unstable
|
213
|
+
# Send email notification email for every unstable build
|
214
|
+
def add_email_notification(params)
|
215
|
+
raise "No job name specified" unless params[:name]
|
216
|
+
raise "No email address specified" unless params[:notification_email]
|
217
|
+
xml = get_config(params[:name])
|
218
|
+
n_xml = Nokogiri::XML(xml)
|
219
|
+
if n_xml.xpath("//hudson.tasks.Mailer").empty?
|
220
|
+
p_xml = Nokogiri::XML::Builder.new(:encoding => "UTF-8") { |xml|
|
221
|
+
notification_email(params, xml)
|
222
|
+
}
|
223
|
+
email_xml = Nokogiri::XML(p_xml.to_xml).xpath(
|
224
|
+
"//hudson.tasks.Mailer"
|
225
|
+
).first
|
226
|
+
n_xml.xpath("//publishers").first.add_child(email_xml)
|
227
|
+
post_config(params[:name], n_xml.to_xml)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
291
231
|
# Adding skype notificaiton to a job
|
292
232
|
#
|
293
233
|
# @param [Hash] params parameters for adding skype notification
|
@@ -313,7 +253,6 @@ module JenkinsApi
|
|
313
253
|
raise "No Skype target specified" unless params[:skype_targets]
|
314
254
|
xml = get_config(params[:name])
|
315
255
|
n_xml = Nokogiri::XML(xml)
|
316
|
-
puts n_xml.xpath("//hudson.plugins.skype.im.transport.SkypePublisher")
|
317
256
|
if n_xml.xpath("//hudson.plugins.skype.im.transport.SkypePublisher").empty?
|
318
257
|
p_xml = Nokogiri::XML::Builder.new(:encoding => "UTF-8") { |xml|
|
319
258
|
skype_notification(params, xml)
|
@@ -399,7 +338,7 @@ module JenkinsApi
|
|
399
338
|
# @return [Hash] response
|
400
339
|
# * +output+ Console output of the job
|
401
340
|
# * +size+ Size of the text. This can be used as 'start' for the
|
402
|
-
#
|
341
|
+
# next call to get progressive output
|
403
342
|
# * +more+ More data available for the job. 'true' if available
|
404
343
|
# and nil otherwise
|
405
344
|
#
|
@@ -817,31 +756,6 @@ module JenkinsApi
|
|
817
756
|
params_array
|
818
757
|
end
|
819
758
|
|
820
|
-
# Obtains the threshold params used by jenkins in the XML file
|
821
|
-
# given the threshold
|
822
|
-
#
|
823
|
-
# @param [String] threshold success, failure, or unstable
|
824
|
-
#
|
825
|
-
# @return [String] status readable status matching the color
|
826
|
-
#
|
827
|
-
def get_threshold_params(threshold)
|
828
|
-
case threshold
|
829
|
-
when 'success'
|
830
|
-
name = 'SUCCESS'
|
831
|
-
ordinal = 0
|
832
|
-
color = 'BLUE'
|
833
|
-
when 'unstable'
|
834
|
-
name = 'UNSTABLE'
|
835
|
-
ordinal = 1
|
836
|
-
color = 'YELLOW'
|
837
|
-
when 'failure'
|
838
|
-
name = 'FAILURE'
|
839
|
-
ordinal = 2
|
840
|
-
color = 'RED'
|
841
|
-
end
|
842
|
-
return name, ordinal, color
|
843
|
-
end
|
844
|
-
|
845
759
|
# Add downstream projects to a specific job given the job name,
|
846
760
|
# projects to be added as downstream projects, and the threshold
|
847
761
|
#
|
@@ -999,6 +913,130 @@ module JenkinsApi
|
|
999
913
|
|
1000
914
|
private
|
1001
915
|
|
916
|
+
# Obtains the threshold params used by jenkins in the XML file
|
917
|
+
# given the threshold
|
918
|
+
#
|
919
|
+
# @param [String] threshold success, failure, or unstable
|
920
|
+
#
|
921
|
+
# @return [String] status readable status matching the color
|
922
|
+
#
|
923
|
+
def get_threshold_params(threshold)
|
924
|
+
case threshold
|
925
|
+
when 'success'
|
926
|
+
name = 'SUCCESS'
|
927
|
+
ordinal = 0
|
928
|
+
color = 'BLUE'
|
929
|
+
when 'unstable'
|
930
|
+
name = 'UNSTABLE'
|
931
|
+
ordinal = 1
|
932
|
+
color = 'YELLOW'
|
933
|
+
when 'failure'
|
934
|
+
name = 'FAILURE'
|
935
|
+
ordinal = 2
|
936
|
+
color = 'RED'
|
937
|
+
end
|
938
|
+
return name, ordinal, color
|
939
|
+
end
|
940
|
+
|
941
|
+
# This private method builds portion of XML that adds subversion SCM
|
942
|
+
# to a Job
|
943
|
+
#
|
944
|
+
# @param [Hash] params parameters to be used for building XML
|
945
|
+
# @param [XML] xml Nokogiri XML object
|
946
|
+
#
|
947
|
+
def scm_subversion(params, xml)
|
948
|
+
xml.scm(:class => "hudson.scm.SubversionSCM",
|
949
|
+
:plugin => "subversion@1.39") {
|
950
|
+
xml.locations {
|
951
|
+
xml.send("hudson.scm.SubversionSCM_-ModuleLocation") {
|
952
|
+
xml.remote "#{params[:scm_url]}"
|
953
|
+
xml.local "."
|
954
|
+
}
|
955
|
+
}
|
956
|
+
xml.excludedRegions
|
957
|
+
xml.includedRegions
|
958
|
+
xml.excludedUsers
|
959
|
+
xml.excludedRevprop
|
960
|
+
xml.excludedCommitMessages
|
961
|
+
xml.workspaceUpdater(:class =>
|
962
|
+
"hudson.scm.subversion.UpdateUpdater")
|
963
|
+
}
|
964
|
+
end
|
965
|
+
|
966
|
+
# This private method builds portion of XML that adds CVS SCM to a Job
|
967
|
+
#
|
968
|
+
# @param [Hash] params parameters to be used for building XML
|
969
|
+
# @param [XML] xml Nokogiri XML object
|
970
|
+
#
|
971
|
+
def scm_cvs(params, xml)
|
972
|
+
xml.scm(:class => "hudson.scm.CVSSCM",
|
973
|
+
:plugin => "cvs@1.6") {
|
974
|
+
xml.cvsroot "#{params[:scm_url]}"
|
975
|
+
xml.module "#{params[:scm_module]}"
|
976
|
+
if params[:scm_branch]
|
977
|
+
xml.branch "#{params[:scm_branch]}"
|
978
|
+
else
|
979
|
+
xml.branch "#{params[:scm_tag]}"
|
980
|
+
end
|
981
|
+
xml.canUseUpdate true
|
982
|
+
xml.useHeadIfNotFound(
|
983
|
+
"#{params[:scm_use_head_if_tag_not_found]}")
|
984
|
+
xml.flatten true
|
985
|
+
if params[:scm_tag]
|
986
|
+
xml.isTag true
|
987
|
+
else
|
988
|
+
xml.isTag false
|
989
|
+
end
|
990
|
+
xml.excludedRegions
|
991
|
+
}
|
992
|
+
end
|
993
|
+
|
994
|
+
# This private method adds portion of XML that adds Git SCM to a Job
|
995
|
+
#
|
996
|
+
# @param [Hash] params parameters to be used for building XML
|
997
|
+
# @param [XML] xml Nokogiri XML object
|
998
|
+
#
|
999
|
+
def scm_git(params, xml)
|
1000
|
+
xml.scm(:class => "hudson.plugins.git.GitSCM") {
|
1001
|
+
xml.configVersion "2"
|
1002
|
+
xml.userRemoteConfigs {
|
1003
|
+
xml.send("hudson.plugins.git.UserRemoteConfig") {
|
1004
|
+
xml.name
|
1005
|
+
xml.refspec
|
1006
|
+
xml.url "#{params[:scm_url]}"
|
1007
|
+
}
|
1008
|
+
}
|
1009
|
+
xml.branches {
|
1010
|
+
xml.send("hudson.plugins.git.BranchSpec") {
|
1011
|
+
xml.name "#{params[:scm_branch]}"
|
1012
|
+
}
|
1013
|
+
}
|
1014
|
+
xml.disableSubmodules "false"
|
1015
|
+
xml.recursiveSubmodules "false"
|
1016
|
+
xml.doGenerateSubmoduleConfigurations "false"
|
1017
|
+
xml.authorOrCommitter "false"
|
1018
|
+
xml.clean "false"
|
1019
|
+
xml.wipeOutWorkspace "false"
|
1020
|
+
xml.pruneBranches "false"
|
1021
|
+
xml.remotePoll "false"
|
1022
|
+
xml.ignoreNotifyCommit "false"
|
1023
|
+
xml.useShallowClone "false"
|
1024
|
+
xml.buildChooser(:class =>
|
1025
|
+
"hudson.plugins.git.util.DefaultBuildChooser")
|
1026
|
+
xml.gitTool "Default"
|
1027
|
+
xml.submoduleCfg(:class => "list")
|
1028
|
+
xml.relativeTargetDir
|
1029
|
+
xml.reference
|
1030
|
+
xml.excludedRegions
|
1031
|
+
xml.excludedUsers
|
1032
|
+
xml.gitConfigName
|
1033
|
+
xml.gitConfigEmail
|
1034
|
+
xml.skipTag "false"
|
1035
|
+
xml.includedRegions
|
1036
|
+
xml.scmName
|
1037
|
+
}
|
1038
|
+
end
|
1039
|
+
|
1002
1040
|
# Method for creating portion of xml that builds Skype notification
|
1003
1041
|
# Use this option only when you have the Skype plugin installed and
|
1004
1042
|
# everything is set up properly
|
@@ -1069,6 +1107,42 @@ module JenkinsApi
|
|
1069
1107
|
}
|
1070
1108
|
end
|
1071
1109
|
|
1110
|
+
# This private method builds portion of XML that adds notification email
|
1111
|
+
# to a Job.
|
1112
|
+
#
|
1113
|
+
# @param [Hash] params parameters to be used for building XML
|
1114
|
+
# @param [XML] xml Nokogiri XML object
|
1115
|
+
#
|
1116
|
+
def notification_email(params, xml)
|
1117
|
+
if params[:notification_email]
|
1118
|
+
xml.send("hudson.tasks.Mailer") {
|
1119
|
+
xml.recipients "#{params[:notification_email]}"
|
1120
|
+
xml.dontNotifyEveryUnstableBuild(
|
1121
|
+
"#{params[:notification_email_for_every_unstable]}")
|
1122
|
+
xml.sendToIndividuals(
|
1123
|
+
"#{params[:notification_email_send_to_individuals]}")
|
1124
|
+
}
|
1125
|
+
end
|
1126
|
+
end
|
1127
|
+
|
1128
|
+
# This private method builds portion of XML that adds child projects
|
1129
|
+
# to a Job.
|
1130
|
+
#
|
1131
|
+
# @param [Hash] params parameters to be used for building XML
|
1132
|
+
# @param [XML] xml Nokogiri XML object
|
1133
|
+
#
|
1134
|
+
def child_projects(params, xml)
|
1135
|
+
xml.send("hudson.tasks.BuildTrigger") {
|
1136
|
+
xml.childProjects "#{params[:child_projects]}"
|
1137
|
+
threshold = params[:child_threshold]
|
1138
|
+
name, ordinal, color = get_threshold_params(threshold)
|
1139
|
+
xml.threshold {
|
1140
|
+
xml.name "#{name}"
|
1141
|
+
xml.ordinal "#{ordinal}"
|
1142
|
+
xml.color "#{color}"
|
1143
|
+
}
|
1144
|
+
}
|
1145
|
+
end
|
1072
1146
|
end
|
1073
1147
|
end
|
1074
1148
|
end
|