jenkins_api_client 1.0.0.beta.4 → 1.0.0.beta.5
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/Gemfile +1 -0
- data/Vagrantfile +4 -4
- data/lib/jenkins_api_client/client.rb +6 -9
- data/lib/jenkins_api_client/exceptions.rb +2 -2
- data/lib/jenkins_api_client/node.rb +6 -3
- data/lib/jenkins_api_client/version.rb +1 -1
- data/scripts/login_with_pry.rb +54 -0
- metadata +19 -2
data/Gemfile
CHANGED
data/Vagrantfile
CHANGED
@@ -6,7 +6,7 @@ Vagrant.configure("2") do |config|
|
|
6
6
|
# options are documented and commented below. For a complete reference,
|
7
7
|
# please see the online documentation at vagrantup.com.
|
8
8
|
|
9
|
-
config.vm.hostname = "jenkins
|
9
|
+
config.vm.hostname = "jenkins"
|
10
10
|
|
11
11
|
# Every Vagrant virtual environment requires a box to build off of.
|
12
12
|
config.vm.box = "opscode-ubuntu-12.04"
|
@@ -19,7 +19,7 @@ Vagrant.configure("2") do |config|
|
|
19
19
|
# via the IP. Host-only networks can talk to the host machine as well as
|
20
20
|
# any other machines on the same network, but cannot be accessed (through this
|
21
21
|
# network interface) by any external networks.
|
22
|
-
config.vm.network :private_network, ip: "33.33.33.
|
22
|
+
config.vm.network :private_network, ip: "33.33.33.100"
|
23
23
|
|
24
24
|
# Create a public network, which generally matched to bridged network.
|
25
25
|
# Bridged networks make the machine appear as another physical device on
|
@@ -78,6 +78,6 @@ Vagrant.configure("2") do |config|
|
|
78
78
|
" sudo gem1.9.1 install bundler;" +
|
79
79
|
" bundle install;" +
|
80
80
|
" travis/setup.sh;" +
|
81
|
-
" bundle exec rake unit_tests;"
|
82
|
-
" bundle exec rake func_tests"
|
81
|
+
" bundle exec rake unit_tests;"
|
82
|
+
#" bundle exec rake func_tests"
|
83
83
|
end
|
@@ -60,7 +60,8 @@ module JenkinsApi
|
|
60
60
|
"timeout",
|
61
61
|
"ssl",
|
62
62
|
"follow_redirects",
|
63
|
-
"identity_file"
|
63
|
+
"identity_file",
|
64
|
+
"cookies"
|
64
65
|
].freeze
|
65
66
|
|
66
67
|
# Initialize a Client object with Jenkins CI server credentials
|
@@ -87,6 +88,7 @@ module JenkinsApi
|
|
87
88
|
# @option args [String] :log_location (STDOUT) the location for the log file
|
88
89
|
# @option args [Fixnum] :log_level (Logger::INFO) The level for messages to be logged. Should be one of:
|
89
90
|
# Logger::DEBUG (0), Logger::INFO (1), Logger::WARN (2), Logger::ERROR (2), Logger::FATAL (3)
|
91
|
+
# @option args [String] :cookies Cookies to be sent with all requests in the format: name=value; name2=value2
|
90
92
|
#
|
91
93
|
# @return [JenkinsApi::Client] a client object to Jenkins API
|
92
94
|
#
|
@@ -249,6 +251,7 @@ module JenkinsApi
|
|
249
251
|
#
|
250
252
|
def make_http_request(request, follow_redirect = @follow_redirects)
|
251
253
|
request.basic_auth @username, @password if @username
|
254
|
+
request['Cookie'] = @cookies if @cookies
|
252
255
|
|
253
256
|
if @proxy_ip
|
254
257
|
http = Net::HTTP::Proxy(@proxy_ip, @proxy_port).new(@server_ip, @server_port)
|
@@ -339,7 +342,6 @@ module JenkinsApi
|
|
339
342
|
# that barf with empty post
|
340
343
|
request = Net::HTTP::Post.new("#{@jenkins_path}#{url_prefix}")
|
341
344
|
@logger.info "POST #{url_prefix}"
|
342
|
-
request.content_type = 'application/json'
|
343
345
|
if @crumbs_enabled
|
344
346
|
request[@crumb["crumbRequestField"]] = @crumb["crumb"]
|
345
347
|
end
|
@@ -544,13 +546,8 @@ module JenkinsApi
|
|
544
546
|
# @return [String] The output of the executed groovy script
|
545
547
|
#
|
546
548
|
def exec_script(script_text)
|
547
|
-
|
548
|
-
|
549
|
-
request.form_data = { 'script' => script_text }
|
550
|
-
@logger.info "POST #{url}"
|
551
|
-
|
552
|
-
response = make_http_request(request)
|
553
|
-
handle_exception(response, 'body')
|
549
|
+
response = api_post_request('/scriptText', {'script' => script_text}, true)
|
550
|
+
response.body
|
554
551
|
end
|
555
552
|
|
556
553
|
# Execute the Jenkins CLI
|
@@ -196,11 +196,11 @@ module JenkinsApi
|
|
196
196
|
end
|
197
197
|
|
198
198
|
# This exception class handles cases where the Jenkins API returns with a
|
199
|
-
# 500
|
199
|
+
# 500 Internal Server Error.
|
200
200
|
#
|
201
201
|
class InternalServerError < ApiException
|
202
202
|
def initialize(logger, message = "", log_level = Logger::ERROR)
|
203
|
-
message = "
|
203
|
+
message = "Internal Server Error. Perhaps the in-memory configuration" +
|
204
204
|
" Jenkins is different from the disk configuration. Please try to" +
|
205
205
|
" reload the configuration" if message.nil? || message.empty?
|
206
206
|
super(logger, message)
|
@@ -20,12 +20,15 @@
|
|
20
20
|
# THE SOFTWARE.
|
21
21
|
#
|
22
22
|
|
23
|
+
require 'jenkins_api_client/urihelper'
|
24
|
+
|
23
25
|
module JenkinsApi
|
24
26
|
class Client
|
25
27
|
# This class communicates with Jenkins "/computer" API to obtain details
|
26
28
|
# about nodes or slaves connected to the Jenkins.
|
27
29
|
#
|
28
30
|
class Node
|
31
|
+
include JenkinsApi::UriHelper
|
29
32
|
|
30
33
|
# General attributes of a node.
|
31
34
|
# This allows the following methods to be called on this node object.
|
@@ -186,7 +189,7 @@ module JenkinsApi
|
|
186
189
|
def delete(node_name)
|
187
190
|
@logger.info "Deleting node '#{node_name}'"
|
188
191
|
if list.include?(node_name)
|
189
|
-
@client.api_post_request("/computer/#{node_name}/doDelete")
|
192
|
+
@client.api_post_request("/computer/#{path_encode node_name}/doDelete")
|
190
193
|
else
|
191
194
|
raise "The specified node '#{node_name}' doesn't exist in Jenkins."
|
192
195
|
end
|
@@ -284,7 +287,7 @@ module JenkinsApi
|
|
284
287
|
def get_config(node_name)
|
285
288
|
@logger.info "Obtaining the config.xml of node '#{node_name}'"
|
286
289
|
node_name = "(master)" if node_name == "master"
|
287
|
-
@client.get_config("/computer/#{node_name}")
|
290
|
+
@client.get_config("/computer/#{ path_encode node_name}")
|
288
291
|
end
|
289
292
|
|
290
293
|
# Posts the given config.xml to the Jenkins node
|
@@ -295,7 +298,7 @@ module JenkinsApi
|
|
295
298
|
def post_config(node_name, xml)
|
296
299
|
@logger.info "Posting the config.xml of node '#{node_name}'"
|
297
300
|
node_name = "(master)" if node_name == "master"
|
298
|
-
@client.post_config("/computer/#{node_name}/config.xml", xml)
|
301
|
+
@client.post_config("/computer/#{path_encode node_name}/config.xml", xml)
|
299
302
|
end
|
300
303
|
|
301
304
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby1.9.1
|
2
|
+
# This script provides an easier way to login to Jenkins server API.
|
3
|
+
# It logs you in with the credentials and server details you proided and then
|
4
|
+
# starts an IRB session so you can interactively play with the API.
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
7
|
+
require 'jenkins_api_client'
|
8
|
+
require 'yaml'
|
9
|
+
require 'pry'
|
10
|
+
|
11
|
+
def prompt_for_username
|
12
|
+
get_from_stdin("Username: ", false)
|
13
|
+
end
|
14
|
+
|
15
|
+
def prompt_for_password
|
16
|
+
get_from_stdin("Password: ", true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_from_stdin(prompt, mask = false)
|
20
|
+
$stdout.write(prompt)
|
21
|
+
|
22
|
+
begin
|
23
|
+
Kernel::system "stty -echo" if mask == true
|
24
|
+
ret = gets.chomp!
|
25
|
+
ensure
|
26
|
+
if mask == true
|
27
|
+
Kernel::system "stty echo"
|
28
|
+
puts ""
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
ret
|
33
|
+
end
|
34
|
+
|
35
|
+
if ARGV.empty?
|
36
|
+
config_file = '~/.jenkins_api_client/spec.yml'
|
37
|
+
else
|
38
|
+
config_file = ARGV.shift
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
client_opts = YAML.load_file(File.expand_path(config_file))
|
43
|
+
unless client_opts.has_key?(:username)
|
44
|
+
client_opts[:username] = prompt_for_username()
|
45
|
+
end
|
46
|
+
unless client_opts.has_key?(:password) or client_opts.has_key?(:password_base64)
|
47
|
+
client_opts[:password] = prompt_for_password()
|
48
|
+
end
|
49
|
+
|
50
|
+
@client = JenkinsApi::Client.new(client_opts)
|
51
|
+
puts "logged-in to the Jenkins API, use the '@client' variable to use the client"
|
52
|
+
end
|
53
|
+
|
54
|
+
Pry.start
|
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: 1.0.0.beta.
|
4
|
+
version: 1.0.0.beta.5
|
5
5
|
prerelease: 6
|
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: 2014-
|
12
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -187,6 +187,22 @@ dependencies:
|
|
187
187
|
- - ! '>='
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '0'
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: pry
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
type: :development
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
190
206
|
description: ! '
|
191
207
|
|
192
208
|
This is a simple and easy-to-use Jenkins Api client with features focused on
|
@@ -232,6 +248,7 @@ files:
|
|
232
248
|
- lib/jenkins_api_client/version.rb
|
233
249
|
- lib/jenkins_api_client/view.rb
|
234
250
|
- scripts/login_with_irb.rb
|
251
|
+
- scripts/login_with_pry.rb
|
235
252
|
- spec/func_tests/client_spec.rb
|
236
253
|
- spec/func_tests/job_spec.rb
|
237
254
|
- spec/func_tests/node_spec.rb.pending
|