jenkins_api_client 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGELOG.md +30 -1
- data/CONTRIBUTORS.md +13 -0
- data/README.md +126 -66
- data/Vagrantfile +85 -0
- data/config/login.yml.example +4 -0
- data/jenkins_api_client.gemspec +12 -12
- data/lib/jenkins_api_client/build_queue.rb +34 -0
- data/lib/jenkins_api_client/cli/job.rb +4 -11
- data/lib/jenkins_api_client/client.rb +241 -79
- data/lib/jenkins_api_client/exceptions.rb +109 -21
- data/lib/jenkins_api_client/job.rb +143 -28
- data/lib/jenkins_api_client/node.rb +16 -8
- data/lib/jenkins_api_client/system.rb +21 -2
- data/lib/jenkins_api_client/version.rb +2 -2
- data/lib/jenkins_api_client/view.rb +18 -1
- data/spec/func_tests/client_spec.rb +9 -15
- data/spec/func_tests/job_spec.rb +190 -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/view_spec.rb +101 -34
- data/spec/unit_tests/build_queue_spec.rb +4 -0
- data/spec/unit_tests/client_spec.rb +2 -36
- data/spec/unit_tests/job_spec.rb +48 -5
- data/spec/unit_tests/node_spec.rb +4 -7
- data/spec/unit_tests/spec_helper.rb +1 -0
- data/spec/unit_tests/system_spec.rb +15 -2
- data/spec/unit_tests/view_spec.rb +11 -7
- data/travis/jenkins_config_with_crumb.xml +67 -0
- data/travis/setup_crumb.sh +11 -0
- data/travis/spec.yml +4 -0
- metadata +158 -140
@@ -90,6 +90,7 @@ module JenkinsApi
|
|
90
90
|
#
|
91
91
|
def initialize(client)
|
92
92
|
@client = client
|
93
|
+
@logger = @client.logger
|
93
94
|
end
|
94
95
|
|
95
96
|
# Gives the string representation of the Object
|
@@ -121,16 +122,13 @@ module JenkinsApi
|
|
121
122
|
# )
|
122
123
|
#
|
123
124
|
def create_dump_slave(params)
|
124
|
-
|
125
|
-
if list.include?(params[:name])
|
126
|
-
raise "The specified slave '#{params[:name]}' already exists."
|
127
|
-
end
|
128
|
-
|
129
125
|
unless params[:name] && params[:slave_host] && params[:private_key_file]
|
130
|
-
raise "Name, slave host, and private key file are
|
131
|
-
" creating a slave."
|
126
|
+
raise ArgumentError, "Name, slave host, and private key file are" +
|
127
|
+
" required for creating a slave."
|
132
128
|
end
|
133
129
|
|
130
|
+
@logger.info "Creating a dump slave '#{params[:name]}'"
|
131
|
+
@logger.debug "Creating a dump slave with params: #{params.inspect}"
|
134
132
|
default_params = {
|
135
133
|
:description => "Automatically created through jenkins_api_client",
|
136
134
|
:executors => 2,
|
@@ -170,7 +168,8 @@ module JenkinsApi
|
|
170
168
|
}
|
171
169
|
}.to_json
|
172
170
|
}
|
173
|
-
|
171
|
+
@logger.debug "Modified params posted to create slave:" +
|
172
|
+
" #{post_params.inspect}"
|
174
173
|
@client.api_post_request("/computer/doCreateItem", post_params)
|
175
174
|
end
|
176
175
|
|
@@ -179,6 +178,7 @@ module JenkinsApi
|
|
179
178
|
# @param [String] node_name Name of the node to delete
|
180
179
|
#
|
181
180
|
def delete(node_name)
|
181
|
+
@logger.info "Deleting node '#{node_name}'"
|
182
182
|
if list.include?(node_name)
|
183
183
|
@client.api_post_request("/computer/#{node_name}/doDelete")
|
184
184
|
else
|
@@ -193,6 +193,7 @@ module JenkinsApi
|
|
193
193
|
# caution.
|
194
194
|
#
|
195
195
|
def delete_all!
|
196
|
+
@logger.info "Deleting all nodes (except master) from jenkins"
|
196
197
|
list.each { |node| delete(node) unless node == "master" }
|
197
198
|
end
|
198
199
|
|
@@ -202,6 +203,7 @@ module JenkinsApi
|
|
202
203
|
# @param [Bool] ignorecase whether to be case sensitive or not
|
203
204
|
#
|
204
205
|
def list(filter = nil, ignorecase = true)
|
206
|
+
@logger.info "Obtaining nodes from jenkins matching filter '#{filter}'"
|
205
207
|
node_names = []
|
206
208
|
response_json = @client.api_get_request("/computer")
|
207
209
|
response_json["computer"].each do |computer|
|
@@ -227,6 +229,7 @@ module JenkinsApi
|
|
227
229
|
#
|
228
230
|
GENERAL_ATTRIBUTES.each do |meth_suffix|
|
229
231
|
define_method("get_#{meth_suffix}") do
|
232
|
+
@logger.info "Obtaining '#{meth_suffix}' attribute from jenkins"
|
230
233
|
response_json = @client.api_get_request("/computer")
|
231
234
|
response_json["#{meth_suffix}"]
|
232
235
|
end
|
@@ -236,6 +239,7 @@ module JenkinsApi
|
|
236
239
|
#
|
237
240
|
NODE_PROPERTIES.each do |meth_suffix|
|
238
241
|
define_method("is_#{meth_suffix}?") do |node_name|
|
242
|
+
@logger.info "Obtaining '#{meth_suffix}' property of '#{node_name}'"
|
239
243
|
response_json = @client.api_get_request("/computer")
|
240
244
|
resp = response_json["computer"][index(node_name)]["#{meth_suffix}"]
|
241
245
|
resp =~ /False/i ? false : true
|
@@ -245,6 +249,7 @@ module JenkinsApi
|
|
245
249
|
# Defines methods for node specific attributes.
|
246
250
|
NODE_ATTRIBUTES.each do |meth_suffix|
|
247
251
|
define_method("get_node_#{meth_suffix}") do |node_name|
|
252
|
+
@logger.info "Obtaining '#{meth_suffix}' attribute of '#{node_name}'"
|
248
253
|
response_json = @client.api_get_request("/computer")
|
249
254
|
response_json["computer"][index(node_name)]["#{meth_suffix}"]
|
250
255
|
end
|
@@ -256,6 +261,7 @@ module JenkinsApi
|
|
256
261
|
# @param [String] mode mode to change to
|
257
262
|
#
|
258
263
|
def change_mode(node_name, mode)
|
264
|
+
@logger.info "Changing the mode of '#{node_name}' to '#{mode}'"
|
259
265
|
mode = mode.upcase
|
260
266
|
xml = get_config(node_name)
|
261
267
|
n_xml = Nokogiri::XML(xml)
|
@@ -270,6 +276,7 @@ module JenkinsApi
|
|
270
276
|
# @param [String] node_name name of the node
|
271
277
|
#
|
272
278
|
def get_config(node_name)
|
279
|
+
@logger.info "Obtaining the config.xml of node '#{node_name}'"
|
273
280
|
node_name = "(master)" if node_name == "master"
|
274
281
|
@client.get_config("/computer/#{node_name}")
|
275
282
|
end
|
@@ -280,6 +287,7 @@ module JenkinsApi
|
|
280
287
|
# @param [String] xml Config.xml of the node
|
281
288
|
#
|
282
289
|
def post_config(node_name, xml)
|
290
|
+
@logger.info "Posting the config.xml of node '#{node_name}'"
|
283
291
|
node_name = "(master)" if node_name == "master"
|
284
292
|
@client.post_config("/computer/#{node_name}/config.xml", xml)
|
285
293
|
end
|
@@ -35,6 +35,8 @@ module JenkinsApi
|
|
35
35
|
#
|
36
36
|
def initialize(client)
|
37
37
|
@client = client
|
38
|
+
@logger = @client.logger
|
39
|
+
@timeout = @client.timeout
|
38
40
|
end
|
39
41
|
|
40
42
|
# Returns a string representation of System class.
|
@@ -46,12 +48,14 @@ module JenkinsApi
|
|
46
48
|
# Sends a quiet down request to the server.
|
47
49
|
#
|
48
50
|
def quiet_down
|
51
|
+
@logger.info "Performing a quiet down of jenkins..."
|
49
52
|
@client.api_post_request("/quietDown")
|
50
53
|
end
|
51
54
|
|
52
55
|
# Cancels the quiet doen request sent to the server.
|
53
56
|
#
|
54
57
|
def cancel_quiet_down
|
58
|
+
@logger.info "Cancelling jenkins form quiet down..."
|
55
59
|
@client.api_post_request("/cancelQuietDown")
|
56
60
|
end
|
57
61
|
|
@@ -62,8 +66,10 @@ module JenkinsApi
|
|
62
66
|
#
|
63
67
|
def restart(force = false)
|
64
68
|
if force
|
69
|
+
@logger.info "Performing a force restart of jenkins..."
|
65
70
|
@client.api_post_request("/restart")
|
66
71
|
else
|
72
|
+
@logger.info "Performing a safe restart of jenkins..."
|
67
73
|
@client.api_post_request("/safeRestart")
|
68
74
|
end
|
69
75
|
end
|
@@ -71,17 +77,30 @@ module JenkinsApi
|
|
71
77
|
# Reload the Jenkins server
|
72
78
|
#
|
73
79
|
def reload
|
80
|
+
@logger.info "Reloading jenkins..."
|
74
81
|
@client.api_post_request("/reload")
|
75
82
|
end
|
76
83
|
|
84
|
+
# List all users known to Jenkins by their Full Name
|
85
|
+
#
|
86
|
+
def list_users
|
87
|
+
@logger.info "Obtaining the list of users from jenkins"
|
88
|
+
users = @client.api_get_request("/asynchPeople")
|
89
|
+
names = []
|
90
|
+
users['users'].each { |user|
|
91
|
+
names << user['user']['fullName']
|
92
|
+
} unless users.nil?
|
93
|
+
return names
|
94
|
+
end
|
95
|
+
|
77
96
|
# This method waits till the server becomes ready after a start
|
78
97
|
# or restart.
|
79
98
|
#
|
80
99
|
def wait_for_ready
|
81
|
-
Timeout::timeout(@
|
100
|
+
Timeout::timeout(@timeout) do
|
82
101
|
while true do
|
83
102
|
response = @client.get_root
|
84
|
-
|
103
|
+
@logger.info "Waiting for jenkins to restart..."
|
85
104
|
if (response.body =~ /Please wait while Jenkins is restarting/ ||
|
86
105
|
response.body =~ /Please wait while Jenkins is getting ready to work/)
|
87
106
|
sleep 30
|
@@ -25,9 +25,9 @@ module JenkinsApi
|
|
25
25
|
# Major version of the gem
|
26
26
|
MAJOR = 0
|
27
27
|
# Minor version of the gem
|
28
|
-
MINOR =
|
28
|
+
MINOR = 13
|
29
29
|
# Tiny version of the gem used for patches
|
30
|
-
TINY =
|
30
|
+
TINY = 0
|
31
31
|
# Used for pre-releases
|
32
32
|
PRE = nil
|
33
33
|
# Version String of Jenkins API Client.
|
@@ -34,6 +34,7 @@ module JenkinsApi
|
|
34
34
|
#
|
35
35
|
def initialize(client)
|
36
36
|
@client = client
|
37
|
+
@logger = @client.logger
|
37
38
|
end
|
38
39
|
|
39
40
|
# Return a string representation of the object
|
@@ -49,6 +50,7 @@ module JenkinsApi
|
|
49
50
|
# listview, myview. Default: listview
|
50
51
|
#
|
51
52
|
def create(view_name, type = "listview")
|
53
|
+
@logger.info "Creating a view '#{view_name}' of type '#{type}'"
|
52
54
|
mode = case type
|
53
55
|
when "listview"
|
54
56
|
"hudson.model.ListView"
|
@@ -81,8 +83,15 @@ module JenkinsApi
|
|
81
83
|
# @option params [String] :regex Regular expression to filter jobs that
|
82
84
|
# are to be added to the view
|
83
85
|
#
|
86
|
+
# @raise [ArgumentError] if the required parameter +:name+ is not
|
87
|
+
# specified
|
88
|
+
#
|
84
89
|
def create_list_view(params)
|
90
|
+
# Name is a required parameter. Raise an error if not specified
|
91
|
+
raise ArgumentError, "Name is required for creating view" \
|
92
|
+
unless params.is_a?(Hash) && params[:name]
|
85
93
|
create(params[:name], "listview")
|
94
|
+
@logger.debug "Creating a list view with params: #{params.inspect}"
|
86
95
|
status_filter = case params[:status_filter]
|
87
96
|
when "all_selected_jobs"
|
88
97
|
""
|
@@ -148,6 +157,7 @@ module JenkinsApi
|
|
148
157
|
# @param [String] view_name
|
149
158
|
#
|
150
159
|
def delete(view_name)
|
160
|
+
@logger.info "Deleting view '#{view_name}'"
|
151
161
|
@client.api_post_request("/view/#{view_name}/doDelete")
|
152
162
|
end
|
153
163
|
|
@@ -157,6 +167,7 @@ module JenkinsApi
|
|
157
167
|
# in Jenkins. Please use with caution.
|
158
168
|
#
|
159
169
|
def delete_all!
|
170
|
+
@logger.info "Deleting all views from jenkins"
|
160
171
|
list.each { |view| delete(view) unless view == "All"}
|
161
172
|
end
|
162
173
|
|
@@ -166,8 +177,9 @@ module JenkinsApi
|
|
166
177
|
# @param [Bool] ignorecase whether to be case sensitive or not
|
167
178
|
#
|
168
179
|
def list(filter = "", ignorecase = true)
|
180
|
+
@logger.info "Obtaining views based on filter '#{filter}'"
|
169
181
|
view_names = []
|
170
|
-
response_json = @client.api_get_request("
|
182
|
+
response_json = @client.api_get_request("")
|
171
183
|
response_json["views"].each { |view|
|
172
184
|
if ignorecase
|
173
185
|
view_names << view["name"] if view["name"] =~ /#{filter}/i
|
@@ -193,6 +205,7 @@ module JenkinsApi
|
|
193
205
|
# @return [Array] job_names list of jobs in the specified view
|
194
206
|
#
|
195
207
|
def list_jobs(view_name)
|
208
|
+
@logger.info "Obtaining the jobs present in view '#{view_name}'"
|
196
209
|
job_names = []
|
197
210
|
raise "The view #{view_name} doesn't exists on the server"\
|
198
211
|
unless exists?(view_name)
|
@@ -209,6 +222,7 @@ module JenkinsApi
|
|
209
222
|
# @param [String] job_name
|
210
223
|
#
|
211
224
|
def add_job(view_name, job_name)
|
225
|
+
@logger.info "Adding job '#{job_name}' to view '#{view_name}'"
|
212
226
|
post_msg = "/view/#{view_name}/addJobToView?name=#{job_name}"
|
213
227
|
@client.api_post_request(post_msg)
|
214
228
|
end
|
@@ -219,6 +233,7 @@ module JenkinsApi
|
|
219
233
|
# @param [String] job_name
|
220
234
|
#
|
221
235
|
def remove_job(view_name, job_name)
|
236
|
+
@logger.info "Removing job '#{job_name}' from view '#{view_name}'"
|
222
237
|
post_msg = "/view/#{view_name}/removeJobFromView?name=#{job_name}"
|
223
238
|
@client.api_post_request(post_msg)
|
224
239
|
end
|
@@ -228,6 +243,7 @@ module JenkinsApi
|
|
228
243
|
# @param [String] view_name
|
229
244
|
#
|
230
245
|
def get_config(view_name)
|
246
|
+
@logger.info "Obtaining the configuration of view '#{view_name}'"
|
231
247
|
@client.get_config("/view/#{view_name}")
|
232
248
|
end
|
233
249
|
|
@@ -237,6 +253,7 @@ module JenkinsApi
|
|
237
253
|
# @param [String] xml
|
238
254
|
#
|
239
255
|
def post_config(view_name, xml)
|
256
|
+
@logger.info "Posting the configuration of view '#{view_name}'"
|
240
257
|
@client.post_config("/view/#{view_name}/config.xml", xml)
|
241
258
|
end
|
242
259
|
|
@@ -27,13 +27,6 @@ describe JenkinsApi::Client do
|
|
27
27
|
|
28
28
|
describe "InstanceMethods" do
|
29
29
|
|
30
|
-
describe "#debug" do
|
31
|
-
it "Should be able to toggle the debug value" do
|
32
|
-
value = @client.debug
|
33
|
-
@client.toggle_debug.should_not == value
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
30
|
describe "#initialize" do
|
38
31
|
it "Should be able to initialize with valid credentials" do
|
39
32
|
client1 = JenkinsApi::Client.new(
|
@@ -50,14 +43,15 @@ describe JenkinsApi::Client do
|
|
50
43
|
end
|
51
44
|
|
52
45
|
it "Should fail if wrong credentials are given" do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
46
|
+
client2 = JenkinsApi::Client.new(
|
47
|
+
:server_ip => @server_ip,
|
48
|
+
:username => 'stranger',
|
49
|
+
:password => 'hacked',
|
50
|
+
:log_location => '/dev/null'
|
51
|
+
)
|
52
|
+
expect(
|
53
|
+
lambda { client2.job.list_all }
|
54
|
+
).to raise_error(JenkinsApi::Exceptions::Unauthorized)
|
61
55
|
end
|
62
56
|
end
|
63
57
|
describe "#get_jenkins_version" do
|
data/spec/func_tests/job_spec.rb
CHANGED
@@ -11,13 +11,13 @@ describe JenkinsApi::Client::Job do
|
|
11
11
|
before(:all) do
|
12
12
|
@helper = JenkinsApiSpecHelper::Helper.new
|
13
13
|
@creds_file = '~/.jenkins_api_client/spec.yml'
|
14
|
+
@creds = YAML.load_file(File.expand_path(@creds_file, __FILE__))
|
14
15
|
@job_name_prefix = 'awesome_rspec_test_job'
|
15
16
|
@filter = "^#{@job_name_prefix}.*"
|
16
17
|
@job_name = ''
|
18
|
+
@valid_post_responses = [200, 201, 302]
|
17
19
|
begin
|
18
|
-
@client = JenkinsApi::Client.new(
|
19
|
-
YAML.load_file(File.expand_path(@creds_file, __FILE__))
|
20
|
-
)
|
20
|
+
@client = JenkinsApi::Client.new(@creds)
|
21
21
|
rescue Exception => e
|
22
22
|
puts "WARNING: Credentials are not set properly."
|
23
23
|
puts e.message
|
@@ -54,36 +54,66 @@ describe JenkinsApi::Client::Job do
|
|
54
54
|
it "Should be able to create a job by getting an xml" do
|
55
55
|
xml = @helper.create_job_xml
|
56
56
|
name = "qwerty_nonexistent_job"
|
57
|
-
@
|
57
|
+
@valid_post_responses.should include(
|
58
|
+
@client.job.create(name, xml).to_i
|
59
|
+
)
|
60
|
+
@client.job.list(name).include?(name).should be_true
|
61
|
+
end
|
62
|
+
it "Should raise proper exception when the job already exists" do
|
63
|
+
xml = @helper.create_job_xml
|
64
|
+
name = "the_duplicate_job"
|
65
|
+
@valid_post_responses.should include(
|
66
|
+
@client.job.create(name, xml).to_i
|
67
|
+
)
|
58
68
|
@client.job.list(name).include?(name).should be_true
|
69
|
+
expect(
|
70
|
+
lambda { @client.job.create(name, xml) }
|
71
|
+
).to raise_error(JenkinsApi::Exceptions::JobAlreadyExists)
|
72
|
+
@valid_post_responses.should include(
|
73
|
+
@client.job.delete(name).to_i
|
74
|
+
)
|
59
75
|
end
|
60
76
|
end
|
61
77
|
|
62
78
|
describe "#create_freestyle" do
|
63
79
|
|
64
|
-
def test_and_validate(name, params)
|
65
|
-
@
|
80
|
+
def test_and_validate(name, params, config_line = nil)
|
81
|
+
@valid_post_responses.should include(
|
82
|
+
@client.job.create_freestyle(params).to_i
|
83
|
+
)
|
66
84
|
@client.job.list(name).include?(name).should be_true
|
67
|
-
|
85
|
+
# Test for the existense of the given line in the config.xml of the
|
86
|
+
# job created
|
87
|
+
unless config_line.nil?
|
88
|
+
config = @client.job.get_config(name)
|
89
|
+
config.should =~ /#{config_line}/
|
90
|
+
end
|
91
|
+
@valid_post_responses.should include(
|
92
|
+
@client.job.delete(name).to_i
|
93
|
+
)
|
68
94
|
@client.job.list(name).include?(name).should be_false
|
69
95
|
end
|
70
96
|
|
71
|
-
it "Should
|
97
|
+
it "Should create a freestyle job with just name" do
|
72
98
|
name = "test_job_name_using_params"
|
73
99
|
params = {
|
74
100
|
:name => name
|
75
101
|
}
|
76
102
|
test_and_validate(name, params)
|
77
103
|
end
|
78
|
-
it "Should
|
104
|
+
it "Should create a freestyle job with shell command" do
|
79
105
|
name = "test_job_using_params_shell"
|
80
106
|
params = {
|
81
107
|
:name => name,
|
82
108
|
:shell_command => "echo this is a free style project"
|
83
109
|
}
|
84
|
-
test_and_validate(
|
110
|
+
test_and_validate(
|
111
|
+
name,
|
112
|
+
params,
|
113
|
+
"<command>echo this is a free style project</command>"
|
114
|
+
)
|
85
115
|
end
|
86
|
-
it "Should
|
116
|
+
it "Should create a freestyle job with Git SCM provider" do
|
87
117
|
name = "test_job_with_git_scm"
|
88
118
|
params = {
|
89
119
|
:name => name,
|
@@ -91,9 +121,13 @@ describe JenkinsApi::Client::Job do
|
|
91
121
|
:scm_url => "git://github.com./arangamani/jenkins_api_client.git",
|
92
122
|
:scm_branch => "master"
|
93
123
|
}
|
94
|
-
test_and_validate(
|
124
|
+
test_and_validate(
|
125
|
+
name,
|
126
|
+
params,
|
127
|
+
"<url>git://github.com./arangamani/jenkins_api_client.git</url>"
|
128
|
+
)
|
95
129
|
end
|
96
|
-
it "Should
|
130
|
+
it "Should create a freestyle job with SVN SCM provider" do
|
97
131
|
name = "test_job_with_subversion_scm"
|
98
132
|
params = {
|
99
133
|
:name => name,
|
@@ -101,9 +135,13 @@ describe JenkinsApi::Client::Job do
|
|
101
135
|
:scm_url => "http://svn.freebsd.org/base/",
|
102
136
|
:scm_branch => "master"
|
103
137
|
}
|
104
|
-
test_and_validate(
|
138
|
+
test_and_validate(
|
139
|
+
name,
|
140
|
+
params,
|
141
|
+
"<remote>http://svn.freebsd.org/base/</remote>"
|
142
|
+
)
|
105
143
|
end
|
106
|
-
it "Should
|
144
|
+
it "Should create a freestyle job with CVS SCM provider with branch" do
|
107
145
|
name = "test_job_with_cvs_scm_branch"
|
108
146
|
params = {
|
109
147
|
:name => name,
|
@@ -112,9 +150,13 @@ describe JenkinsApi::Client::Job do
|
|
112
150
|
:scm_module => "src",
|
113
151
|
:scm_branch => "MAIN"
|
114
152
|
}
|
115
|
-
test_and_validate(
|
153
|
+
test_and_validate(
|
154
|
+
name,
|
155
|
+
params,
|
156
|
+
"<cvsroot>http://cvs.NetBSD.org</cvsroot>"
|
157
|
+
)
|
116
158
|
end
|
117
|
-
it "Should
|
159
|
+
it "Should create a freestyle job with CVS SCM provider with tag" do
|
118
160
|
name = "test_job_with_cvs_scm_tag"
|
119
161
|
params = {
|
120
162
|
:name => name,
|
@@ -123,9 +165,13 @@ describe JenkinsApi::Client::Job do
|
|
123
165
|
:scm_module => "src",
|
124
166
|
:scm_tag => "MAIN"
|
125
167
|
}
|
126
|
-
test_and_validate(
|
168
|
+
test_and_validate(
|
169
|
+
name,
|
170
|
+
params,
|
171
|
+
"<cvsroot>http://cvs.NetBSD.org</cvsroot>"
|
172
|
+
)
|
127
173
|
end
|
128
|
-
it "Should
|
174
|
+
it "Should raise an error if unsupported SCM is specified" do
|
129
175
|
name = "test_job_unsupported_scm"
|
130
176
|
params = {
|
131
177
|
:name => name,
|
@@ -137,7 +183,7 @@ describe JenkinsApi::Client::Job do
|
|
137
183
|
lambda{ @client.job.create_freestyle(params) }
|
138
184
|
).to raise_error
|
139
185
|
end
|
140
|
-
it "Should
|
186
|
+
it "Should create a freestyle job with restricted_node option" do
|
141
187
|
name = "test_job_restricted_node"
|
142
188
|
params = {
|
143
189
|
:name => name,
|
@@ -145,7 +191,8 @@ describe JenkinsApi::Client::Job do
|
|
145
191
|
}
|
146
192
|
test_and_validate(name, params)
|
147
193
|
end
|
148
|
-
it "Should
|
194
|
+
it "Should create a freestyle job with" +
|
195
|
+
" block_build_when_downstream_building option" do
|
149
196
|
name = "test_job_block_build_when_downstream_building"
|
150
197
|
params = {
|
151
198
|
:name => name,
|
@@ -153,7 +200,8 @@ describe JenkinsApi::Client::Job do
|
|
153
200
|
}
|
154
201
|
test_and_validate(name, params)
|
155
202
|
end
|
156
|
-
it "Should
|
203
|
+
it "Should create a freestyle job with" +
|
204
|
+
" block_build_when_upstream_building option" do
|
157
205
|
name = "test_job_block_build_when_upstream_building"
|
158
206
|
params = {
|
159
207
|
:name => name,
|
@@ -161,7 +209,7 @@ describe JenkinsApi::Client::Job do
|
|
161
209
|
}
|
162
210
|
test_and_validate(name, params)
|
163
211
|
end
|
164
|
-
it "Should
|
212
|
+
it "Should create a freestyle job with concurrent_build option" do
|
165
213
|
name = "test_job_concurrent_build"
|
166
214
|
params = {
|
167
215
|
:name => name,
|
@@ -169,7 +217,7 @@ describe JenkinsApi::Client::Job do
|
|
169
217
|
}
|
170
218
|
test_and_validate(name, params)
|
171
219
|
end
|
172
|
-
it "Should
|
220
|
+
it "Should create a freestyle job with timer option" do
|
173
221
|
name = "test_job_using_timer"
|
174
222
|
params = {
|
175
223
|
:name => name,
|
@@ -177,7 +225,7 @@ describe JenkinsApi::Client::Job do
|
|
177
225
|
}
|
178
226
|
test_and_validate(name, params)
|
179
227
|
end
|
180
|
-
it "Should
|
228
|
+
it "Should create a freestyle job with child projects option" do
|
181
229
|
name = "test_job_child_projects"
|
182
230
|
params = {
|
183
231
|
:name => name,
|
@@ -186,7 +234,7 @@ describe JenkinsApi::Client::Job do
|
|
186
234
|
}
|
187
235
|
test_and_validate(name, params)
|
188
236
|
end
|
189
|
-
it "Should
|
237
|
+
it "Should create a freestyle job with notification_email option" do
|
190
238
|
name = "test_job_notification_email"
|
191
239
|
params = {
|
192
240
|
:name => name,
|
@@ -194,7 +242,8 @@ describe JenkinsApi::Client::Job do
|
|
194
242
|
}
|
195
243
|
test_and_validate(name, params)
|
196
244
|
end
|
197
|
-
it "Should
|
245
|
+
it "Should create a freestyle job with notification for" +
|
246
|
+
" individual skype targets" do
|
198
247
|
name = "test_job_with_individual_skype_targets"
|
199
248
|
params = {
|
200
249
|
:name => name,
|
@@ -202,7 +251,8 @@ describe JenkinsApi::Client::Job do
|
|
202
251
|
}
|
203
252
|
test_and_validate(name, params)
|
204
253
|
end
|
205
|
-
it "Should
|
254
|
+
it "Should create a freestyle job with notification for" +
|
255
|
+
" group skype targets" do
|
206
256
|
name = "test_job_with_group_skype_targets"
|
207
257
|
params = {
|
208
258
|
:name => name,
|
@@ -210,7 +260,8 @@ describe JenkinsApi::Client::Job do
|
|
210
260
|
}
|
211
261
|
test_and_validate(name, params)
|
212
262
|
end
|
213
|
-
it "Should
|
263
|
+
it "Should create a freestyle job with complex skype" +
|
264
|
+
" configuration" do
|
214
265
|
name = "test_job_with_complex_skype_configuration"
|
215
266
|
params = {
|
216
267
|
:name => name,
|
@@ -225,31 +276,83 @@ describe JenkinsApi::Client::Job do
|
|
225
276
|
}
|
226
277
|
test_and_validate(name, params)
|
227
278
|
end
|
279
|
+
it "Should raise an error if the input parameters is not a Hash" do
|
280
|
+
expect(
|
281
|
+
lambda {
|
282
|
+
@client.job.create_freestyle("a_string")
|
283
|
+
}
|
284
|
+
).to raise_error(ArgumentError)
|
285
|
+
end
|
286
|
+
it "Should raise an error if the required name paremeter is missing" do
|
287
|
+
expect(
|
288
|
+
lambda {
|
289
|
+
@client.job.create_freestyle(:shell_command => "sleep 60")
|
290
|
+
}
|
291
|
+
).to raise_error(ArgumentError)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
describe "#copy" do
|
296
|
+
it "accepts the from and to job name and copies the job" do
|
297
|
+
xml = @helper.create_job_xml
|
298
|
+
@client.job.create("from_job_copy_test", xml)
|
299
|
+
@client.job.copy("from_job_copy_test", "to_job_copy_test")
|
300
|
+
@client.job.list(".*_job_copy_test").should == [
|
301
|
+
"from_job_copy_test", "to_job_copy_test"
|
302
|
+
]
|
303
|
+
@client.job.delete("from_job_copy_test")
|
304
|
+
@client.job.delete("to_job_copy_test")
|
305
|
+
end
|
306
|
+
it "accepts the from job name and copies the from job to the" +
|
307
|
+
" copy_of_from job" do
|
308
|
+
xml = @helper.create_job_xml
|
309
|
+
@client.job.create("from_job_copy_test", xml)
|
310
|
+
@client.job.copy("from_job_copy_test")
|
311
|
+
@client.job.list(".*_job_copy_test").should == [
|
312
|
+
"copy_of_from_job_copy_test", "from_job_copy_test"
|
313
|
+
]
|
314
|
+
@client.job.delete("from_job_copy_test")
|
315
|
+
@client.job.delete("copy_of_from_job_copy_test")
|
316
|
+
end
|
228
317
|
end
|
229
318
|
|
230
319
|
describe "#add_email_notification" do
|
231
320
|
it "Should accept email address and add to existing job" do
|
232
321
|
name = "email_notification_test_job"
|
233
322
|
params = {:name => name}
|
234
|
-
@
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
323
|
+
@valid_post_responses.should include(
|
324
|
+
@client.job.create_freestyle(params).to_i
|
325
|
+
)
|
326
|
+
@valid_post_responses.should include(
|
327
|
+
@client.job.add_email_notification(
|
328
|
+
:name => name,
|
329
|
+
:notification_email => "testuser@testdomain.com"
|
330
|
+
).to_i
|
331
|
+
)
|
332
|
+
@valid_post_responses.should include(
|
333
|
+
@client.job.delete(name).to_i
|
334
|
+
)
|
240
335
|
end
|
241
336
|
end
|
242
337
|
|
243
338
|
describe "#add_skype_notification" do
|
244
339
|
it "Should accept skype configuration and add to existing job" do
|
245
340
|
name = "skype_notification_test_job"
|
246
|
-
params = {
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
)
|
252
|
-
@
|
341
|
+
params = {
|
342
|
+
:name => name
|
343
|
+
}
|
344
|
+
@valid_post_responses.should include(
|
345
|
+
@client.job.create_freestyle(params).to_i
|
346
|
+
)
|
347
|
+
@valid_post_responses.should include(
|
348
|
+
@client.job.add_skype_notification(
|
349
|
+
:name => name,
|
350
|
+
:skype_targets => "testuser"
|
351
|
+
).to_i
|
352
|
+
)
|
353
|
+
@valid_post_responses.should include(
|
354
|
+
@client.job.delete(name).to_i
|
355
|
+
)
|
253
356
|
end
|
254
357
|
end
|
255
358
|
|
@@ -268,21 +371,37 @@ describe JenkinsApi::Client::Job do
|
|
268
371
|
|
269
372
|
describe "#recreate" do
|
270
373
|
it "Should be able to re-create a job" do
|
271
|
-
@
|
374
|
+
@valid_post_responses.should include(
|
375
|
+
@client.job.recreate("qwerty_nonexistent_job").to_i
|
376
|
+
)
|
272
377
|
end
|
273
378
|
end
|
274
379
|
|
275
380
|
describe "#change_description" do
|
276
381
|
it "Should be able to change the description of a job" do
|
277
|
-
@
|
278
|
-
"
|
279
|
-
|
382
|
+
@valid_post_responses.should include(
|
383
|
+
@client.job.change_description("qwerty_nonexistent_job",
|
384
|
+
"The description has been changed by the spec test").to_i
|
385
|
+
)
|
280
386
|
end
|
281
387
|
end
|
282
388
|
|
283
389
|
describe "#delete" do
|
284
390
|
it "Should be able to delete a job" do
|
285
|
-
@
|
391
|
+
@valid_post_responses.should include(
|
392
|
+
@client.job.delete("qwerty_nonexistent_job").to_i
|
393
|
+
)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
describe "#wipe_out_workspace" do
|
398
|
+
it "Should be able to wipe out the workspace of a job" do
|
399
|
+
xml = @helper.create_job_xml
|
400
|
+
@client.job.create("wipeout_job_test", xml)
|
401
|
+
@valid_post_responses.should include(
|
402
|
+
@client.job.wipe_out_workspace("wipeout_job_test").to_i
|
403
|
+
)
|
404
|
+
@client.job.delete("wipeout_job_test")
|
286
405
|
end
|
287
406
|
end
|
288
407
|
|
@@ -369,7 +488,7 @@ describe JenkinsApi::Client::Job do
|
|
369
488
|
response = @client.job.build(@job_name)
|
370
489
|
# As of Jenkins version 1.519 the job build responds with a 201
|
371
490
|
# status code.
|
372
|
-
|
491
|
+
@valid_post_responses.should include(response.to_i)
|
373
492
|
# Sleep for 6 seconds so we don't hit the Jenkins quiet period (5
|
374
493
|
# seconds)
|
375
494
|
sleep 6
|
@@ -381,6 +500,20 @@ describe JenkinsApi::Client::Job do
|
|
381
500
|
end
|
382
501
|
end
|
383
502
|
|
503
|
+
describe "#disable" do
|
504
|
+
it "Should disable the specified job and then enable it again" do
|
505
|
+
@client.job.list_details(@job_name)['buildable'].should == true
|
506
|
+
response = @client.job.disable(@job_name)
|
507
|
+
response.to_i.should == 302
|
508
|
+
sleep 3
|
509
|
+
@client.job.list_details(@job_name)['buildable'].should == false
|
510
|
+
response = @client.job.enable(@job_name)
|
511
|
+
response.to_i.should == 302
|
512
|
+
sleep 3
|
513
|
+
@client.job.list_details(@job_name)['buildable'].should == true
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
384
517
|
describe "#stop" do
|
385
518
|
it "Should be able to abort a recent build of a running job" do
|
386
519
|
@client.job.get_current_build_status(
|
@@ -390,7 +523,9 @@ describe JenkinsApi::Client::Job do
|
|
390
523
|
sleep 6
|
391
524
|
@client.job.get_current_build_status(@job_name).should == "running"
|
392
525
|
sleep 5
|
393
|
-
@
|
526
|
+
@valid_post_responses.should include(
|
527
|
+
@client.job.stop_build(@job_name).to_i
|
528
|
+
)
|
394
529
|
sleep 5
|
395
530
|
@client.job.get_current_build_status(@job_name).should == "aborted"
|
396
531
|
end
|
@@ -398,9 +533,13 @@ describe JenkinsApi::Client::Job do
|
|
398
533
|
|
399
534
|
describe "#restrict_to_node" do
|
400
535
|
it "Should be able to restrict a job to a node" do
|
401
|
-
@
|
536
|
+
@valid_post_responses.should include(
|
537
|
+
@client.job.restrict_to_node(@job_name, 'master').to_i
|
538
|
+
)
|
402
539
|
# Run it again to make sure that the replace existing node works
|
403
|
-
@
|
540
|
+
@valid_post_responses.should include(
|
541
|
+
@client.job.restrict_to_node(@job_name, 'master').to_i
|
542
|
+
)
|
404
543
|
end
|
405
544
|
end
|
406
545
|
|