jenkins_api_client 1.0.0.alpha.1 → 1.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,19 +2,12 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 1.9.3
5
- - jruby-18mode
6
5
  - jruby-19mode
7
- - rbx-18mode
8
6
  - rbx-19mode
9
- - 1.8.7
10
- - ree
11
7
  matrix:
12
8
  allow_failures:
13
- - rvm: jruby-18mode
14
9
  - rvm: jruby-19mode
15
- - rvm: rbx-18mode
16
10
  - rvm: rbx-19mode
17
- - rvm: ree
18
11
  before_install:
19
12
  - travis/setup.sh
20
13
 
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "nokogiri", "~> 1.5.0"
3
+ gem "nokogiri", "~> 1.6.0"
4
4
  gem "thor", ">= 0.16.0"
5
5
  gem "json", ">= 0"
6
6
  gem "terminal-table", ">= 1.4.0"
@@ -9,7 +9,7 @@ gem "mixlib-shellout", ">= 1.1.0"
9
9
  group :development do
10
10
  gem "bundler", ">= 1.0"
11
11
  gem "jeweler", ">= 1.6.4"
12
- gem "rspec", "~> 2.13.0"
12
+ gem "rspec", "~> 2.14.1"
13
13
  gem "simplecov"
14
14
  gem "yard-thor"
15
15
  gem "yard"
data/README.md CHANGED
@@ -67,6 +67,14 @@ file. To use the client without credentials, just leave out the
67
67
  <tt>username</tt> and <tt>password</tt> parameters. The <tt>password</tt>
68
68
  parameter is only required if <tt>username</tt> is specified.
69
69
 
70
+ #### Using with Open ID
71
+
72
+ It is very simple to authenticate with your Jenkins server that has Open ID
73
+ authentication enabled. You will have to obtain your API token and use the API
74
+ token as the password. For obtaining the API token, go to your user configuration
75
+ page and click 'Show API Token'. Use this token for the `password` parameter when
76
+ initializing the client.
77
+
70
78
  ### Cross-site Scripting (XSS) and Crumb Support
71
79
 
72
80
  Support for Jenkins crumbs has been added. These allow an application to
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ Jeweler::Tasks.new do |gemspec|
22
22
  This is a simple and easy-to-use Jenkins Api client with features focused on
23
23
  automating Job configuration programaticaly and so forth}
24
24
  gemspec.test_files = `git ls-files -- {spec}/*`.split("\n")
25
+ gemspec.required_ruby_version = '>= 1.9.2'
25
26
  gemspec.rubygems_version = '1.8.17'
26
27
  end
27
28
 
@@ -9,11 +9,11 @@ Vagrant.configure("2") do |config|
9
9
  config.vm.hostname = "jenkins-api-client"
10
10
 
11
11
  # Every Vagrant virtual environment requires a box to build off of.
12
- config.vm.box = "Ubuntu-12.04-LTS"
12
+ config.vm.box = "opscode-ubuntu-12.04"
13
13
 
14
14
  # The url from where the 'config.vm.box' box will be fetched if it
15
15
  # doesn't already exist on the user's system.
16
- config.vm.box_url = "https://s3-us-west-2.amazonaws.com/squishy.vagrant-boxes/precise64_squishy_2013-02-09.box"
16
+ config.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box"
17
17
 
18
18
  # Assign this VM to a host-only network IP, allowing you to access it
19
19
  # via the IP. Host-only networks can talk to the host machine as well as
@@ -73,11 +73,12 @@ Vagrant.configure("2") do |config|
73
73
  config.vm.synced_folder ".", "/opt/jenkins_api_client"
74
74
 
75
75
  config.vm.provision :shell, :inline =>
76
- " sudo apt-get install -y git rubygems libxslt-dev libxml2-dev;" +
76
+ " sudo apt-get update;" +
77
+ " sudo apt-get install -y git ruby1.9.1-full rubygems libxslt-dev libxml2-dev;" +
77
78
  " cd /opt/jenkins_api_client;" +
78
79
  " ls -lrt;" +
79
- " ruby --version;" +
80
- " sudo gem install bundler;" +
80
+ " ruby1.9.1 --version;" +
81
+ " sudo gem1.9.1 install bundler;" +
81
82
  " bundle install;" +
82
83
  " travis/setup.sh;" +
83
84
  " bundle exec rake unit_tests;" +
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "jenkins_api_client"
8
- s.version = "0.14.1"
8
+ s.version = "1.0.0.alpha.2"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kannan Manickam"]
12
- s.date = "2013-08-19"
12
+ s.date = "2013-10-25"
13
13
  s.description = "\nThis is a simple and easy-to-use Jenkins Api client with features focused on\nautomating Job configuration programaticaly and so forth"
14
14
  s.email = ["arangamani.kannan@gmail.com"]
15
15
  s.executables = ["jenkinscli"]
@@ -49,20 +49,26 @@ Gem::Specification.new do |s|
49
49
  "spec/func_tests/client_spec.rb",
50
50
  "spec/func_tests/job_spec.rb",
51
51
  "spec/func_tests/node_spec.rb",
52
+ "spec/func_tests/plugin_spec.rb",
52
53
  "spec/func_tests/spec_helper.rb",
53
54
  "spec/func_tests/system_spec.rb",
54
55
  "spec/func_tests/user_spec.rb",
55
56
  "spec/func_tests/view_spec.rb",
56
57
  "spec/unit_tests/build_queue_spec.rb",
57
58
  "spec/unit_tests/client_spec.rb",
59
+ "spec/unit_tests/fixtures/files/available_plugins.json",
58
60
  "spec/unit_tests/fixtures/files/computer_sample.xml",
61
+ "spec/unit_tests/fixtures/files/installed_plugins.json",
59
62
  "spec/unit_tests/fixtures/files/job_sample.xml",
63
+ "spec/unit_tests/fixtures/files/updatable_plugins.json",
60
64
  "spec/unit_tests/job_spec.rb",
61
65
  "spec/unit_tests/node_spec.rb",
66
+ "spec/unit_tests/plugin_spec.rb",
62
67
  "spec/unit_tests/spec_helper.rb",
63
68
  "spec/unit_tests/system_spec.rb",
64
69
  "spec/unit_tests/user_spec.rb",
65
70
  "spec/unit_tests/view_spec.rb",
71
+ "travis/hudson.model.UpdateCenter.xml",
66
72
  "travis/jenkins_config.xml",
67
73
  "travis/jenkins_config_with_crumb.xml",
68
74
  "travis/setup.sh",
@@ -72,6 +78,7 @@ Gem::Specification.new do |s|
72
78
  ]
73
79
  s.homepage = "https://github.com/arangamani/jenkins_api_client"
74
80
  s.require_paths = ["lib"]
81
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
75
82
  s.rubygems_version = "1.8.23"
76
83
  s.summary = "Jenkins JSON API Client"
77
84
 
@@ -79,38 +86,41 @@ Gem::Specification.new do |s|
79
86
  s.specification_version = 3
80
87
 
81
88
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
- s.add_runtime_dependency(%q<nokogiri>, ["~> 1.5.0"])
89
+ s.add_runtime_dependency(%q<nokogiri>, ["~> 1.6.0"])
83
90
  s.add_runtime_dependency(%q<thor>, [">= 0.16.0"])
84
91
  s.add_runtime_dependency(%q<json>, [">= 0"])
85
92
  s.add_runtime_dependency(%q<terminal-table>, [">= 1.4.0"])
86
93
  s.add_runtime_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
87
94
  s.add_development_dependency(%q<bundler>, [">= 1.0"])
88
95
  s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
89
- s.add_development_dependency(%q<rspec>, ["~> 2.13.0"])
96
+ s.add_development_dependency(%q<rspec>, ["~> 2.14.1"])
90
97
  s.add_development_dependency(%q<simplecov>, [">= 0"])
98
+ s.add_development_dependency(%q<yard-thor>, [">= 0"])
91
99
  s.add_development_dependency(%q<yard>, [">= 0"])
92
100
  else
93
- s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
101
+ s.add_dependency(%q<nokogiri>, ["~> 1.6.0"])
94
102
  s.add_dependency(%q<thor>, [">= 0.16.0"])
95
103
  s.add_dependency(%q<json>, [">= 0"])
96
104
  s.add_dependency(%q<terminal-table>, [">= 1.4.0"])
97
105
  s.add_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
98
106
  s.add_dependency(%q<bundler>, [">= 1.0"])
99
107
  s.add_dependency(%q<jeweler>, [">= 1.6.4"])
100
- s.add_dependency(%q<rspec>, ["~> 2.13.0"])
108
+ s.add_dependency(%q<rspec>, ["~> 2.14.1"])
101
109
  s.add_dependency(%q<simplecov>, [">= 0"])
110
+ s.add_dependency(%q<yard-thor>, [">= 0"])
102
111
  s.add_dependency(%q<yard>, [">= 0"])
103
112
  end
104
113
  else
105
- s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
114
+ s.add_dependency(%q<nokogiri>, ["~> 1.6.0"])
106
115
  s.add_dependency(%q<thor>, [">= 0.16.0"])
107
116
  s.add_dependency(%q<json>, [">= 0"])
108
117
  s.add_dependency(%q<terminal-table>, [">= 1.4.0"])
109
118
  s.add_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
110
119
  s.add_dependency(%q<bundler>, [">= 1.0"])
111
120
  s.add_dependency(%q<jeweler>, [">= 1.6.4"])
112
- s.add_dependency(%q<rspec>, ["~> 2.13.0"])
121
+ s.add_dependency(%q<rspec>, ["~> 2.14.1"])
113
122
  s.add_dependency(%q<simplecov>, [">= 0"])
123
+ s.add_dependency(%q<yard-thor>, [">= 0"])
114
124
  s.add_dependency(%q<yard>, [">= 0"])
115
125
  end
116
126
  end
@@ -401,6 +401,14 @@ module JenkinsApi
401
401
  # @return [String] Response code returned from Jenkins
402
402
  #
403
403
  def post_config(url_prefix, xml)
404
+ post_data(url_prefix, xml, 'application/xml')
405
+ end
406
+
407
+ def post_json(url_prefix, json)
408
+ post_data(url_prefix, json, 'application/json')
409
+ end
410
+
411
+ def post_data(url_prefix, data, content_type)
404
412
  retries = @crumb_max_retries
405
413
  begin
406
414
  refresh_crumbs
@@ -408,8 +416,8 @@ module JenkinsApi
408
416
  url_prefix = URI.escape("#{@jenkins_path}#{url_prefix}")
409
417
  request = Net::HTTP::Post.new("#{url_prefix}")
410
418
  @logger.info "POST #{url_prefix}"
411
- request.body = xml
412
- request.content_type = 'application/xml'
419
+ request.body = data
420
+ request.content_type = content_type
413
421
  if @crumbs_enabled
414
422
  request[@crumb["crumbRequestField"]] = @crumb["crumb"]
415
423
  end
@@ -434,6 +442,24 @@ module JenkinsApi
434
442
  end
435
443
  end
436
444
 
445
+ def init_update_center
446
+ @logger.info "Initializing Jenkins Update Center..."
447
+ @logger.debug "Obtaining the JSON data for Update Center..."
448
+ # TODO: Clean me up
449
+ update_center_data = open("http://updates.jenkins-ci.org/update-center.json").read
450
+ # The Jenkins mirror returns the data in the following format
451
+ # updateCenter.post(
452
+ # {.. JSON data...}
453
+ # );
454
+ # which is used by the Javascript used by the Jenkins UI to send to Jenkins.
455
+ #
456
+ update_center_data.gsub!("updateCenter.post(\n", "")
457
+ update_center_data.gsub!("\n);", "")
458
+
459
+ @logger.debug "Posting the obtained JSON to Jenkins Update Center..."
460
+ post_json("/updateCenter/byId/default/postBack", update_center_data)
461
+ end
462
+
437
463
  # Checks if Jenkins uses crumbs (i.e) the XSS disable option is checked in
438
464
  # Jenkins' security settings
439
465
  #
@@ -202,7 +202,7 @@ module JenkinsApi
202
202
  def initialize(logger, message = "", log_level = Logger::ERROR)
203
203
  message = "Internel Server Error. Perhaps the in-memory configuration" +
204
204
  " Jenkins is different from the disk configuration. Please try to" +
205
- " reload the configuration" if message.empty?
205
+ " reload the configuration" if message.nil? || message.empty?
206
206
  super(logger, message)
207
207
  end
208
208
  end
@@ -124,9 +124,8 @@ module JenkinsApi
124
124
  # )
125
125
  #
126
126
  def create_dump_slave(params)
127
- unless params[:name] && params[:slave_host] && params[:private_key_file]
128
- raise ArgumentError, "Name, slave host, and private key file are" +
129
- " required for creating a slave."
127
+ unless params[:name] && params[:slave_host]
128
+ raise ArgumentError, "Name, slave host are required for creating a slave."
130
129
  end
131
130
 
132
131
  @logger.info "Creating a dump slave '#{params[:name]}'"
@@ -137,7 +136,11 @@ module JenkinsApi
137
136
  :remote_fs => "/var/jenkins",
138
137
  :labels => params[:name],
139
138
  :slave_port => 22,
140
- :mode => "normal"
139
+ :mode => "normal",
140
+ :credential_id => "",
141
+ :java_path => "",
142
+ :prefix_start_slave_cmd => "",
143
+ :suffix_start_slave_cmd => ""
141
144
  }
142
145
 
143
146
  params = default_params.merge(params)
@@ -165,8 +168,13 @@ module JenkinsApi
165
168
  "stapler-class" => "hudson.plugins.sshslaves.SSHLauncher",
166
169
  "host" => params[:slave_host],
167
170
  "port" => params[:slave_port],
168
- "username" => params[:slave_user],
169
- "privatekey" => params[:private_key_file],
171
+ "credentialsId" => params[:credential_id],
172
+ "javaPath" => params[:java_path],
173
+ "jvmOptions" => params[:jvm_options],
174
+ "prefixStartSlaveCmd" => params[:prefix_start_slave_cmd],
175
+ "suffixStartSlaveCmd" => params[:suffix_start_slave_cmd]
176
+ #"username" => params[:slave_user],
177
+ #"privatekey" => params[:private_key_file],
170
178
  }
171
179
  }.to_json
172
180
  }
@@ -294,6 +302,37 @@ module JenkinsApi
294
302
  @client.post_config("/computer/#{node_name}/config.xml", xml)
295
303
  end
296
304
 
305
+
306
+ def create_cred
307
+ post_params = {
308
+ "name" => "testcred",
309
+ "description" => "test cred description",
310
+ "json" => {
311
+ "domainCredentials" => {
312
+ "domain" => {
313
+ "name" => "",
314
+ "description" => "",
315
+ },
316
+ "credentials" => {
317
+ "scope" => "GLOBAL",
318
+ "id" => "",
319
+ "username" => "root",
320
+ "description" => "root users credential",
321
+ "privateKeySource" => {
322
+ "value" => "0",
323
+ "privateKey" => "blah blah blah",
324
+ "stapler-class" => "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource"
325
+ },
326
+ "passphrase" => "",
327
+ "stapler-class" => "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey",
328
+ "kind" => "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"
329
+ }
330
+ }
331
+ }.to_json
332
+ }
333
+ @client.api_post_request("/credentials/configSubmit", post_params)
334
+ end
335
+
297
336
  end
298
337
  end
299
338
  end
@@ -29,7 +29,7 @@ module JenkinsApi
29
29
  # Tiny version of the gem used for patches
30
30
  TINY = 0
31
31
  # Used for pre-releases
32
- PRE = 'alpha.1'
32
+ PRE = 'alpha.2'
33
33
  # Version String of Jenkins API Client.
34
34
  VERSION = [MAJOR, MINOR, TINY, PRE].compact.join('.')
35
35
  end
@@ -65,12 +65,6 @@ describe JenkinsApi::Client do
65
65
  @client.get_hudson_version.class.should == String
66
66
  end
67
67
  end
68
-
69
- describe "#get_server_date" do
70
- it "Should return the server date" do
71
- @client.get_server_date.class.should == String
72
- end
73
- end
74
68
  end
75
69
 
76
70
  describe "SubClassAccessorMethods" do
@@ -17,7 +17,7 @@ describe JenkinsApi::Client::PluginManager do
17
17
  @client = JenkinsApi::Client.new(
18
18
  YAML.load_file(File.expand_path(@creds_file, __FILE__))
19
19
  )
20
- @client.plugin.check_for_updates
20
+ @client.init_update_center
21
21
  sleep 30
22
22
  rescue Exception => e
23
23
  puts "WARNING: Credentials are not set properly."
@@ -70,7 +70,7 @@ describe JenkinsApi::Client::PluginManager do
70
70
  it "installs multiple plugins given as an array" do
71
71
  @client.plugin.install(@test_plugins)
72
72
  # Plugin installation might take a bit
73
- sleep 5
73
+ sleep 15
74
74
  @client.system.restart(true) if @client.plugin.restart_required?
75
75
  @client.system.wait_for_ready
76
76
  installed = @client.plugin.list_installed.keys
@@ -5,7 +5,7 @@ describe JenkinsApi::Client::PluginManager do
5
5
  context "With properly initialized Client" do
6
6
  before do
7
7
  mock_logger = Logger.new "/dev/null"
8
- @client = mock
8
+ @client = double
9
9
  @client.should_receive(:logger).and_return(mock_logger)
10
10
  @plugin = JenkinsApi::Client::PluginManager.new(@client)
11
11
  @installed_plugins = load_json_from_fixture("installed_plugins.json")
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/bin/bash -x
2
2
 
3
3
  # Install Jenkins
4
4
  wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
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.alpha.1
4
+ version: 1.0.0.alpha.2
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: 2013-10-15 00:00:00.000000000 Z
12
+ date: 2013-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.5.0
21
+ version: 1.6.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.5.0
29
+ version: 1.6.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: thor
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ~>
132
132
  - !ruby/object:Gem::Version
133
- version: 2.13.0
133
+ version: 2.14.1
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -138,7 +138,7 @@ dependencies:
138
138
  requirements:
139
139
  - - ~>
140
140
  - !ruby/object:Gem::Version
141
- version: 2.13.0
141
+ version: 2.14.1
142
142
  - !ruby/object:Gem::Dependency
143
143
  name: simplecov
144
144
  requirement: !ruby/object:Gem::Requirement
@@ -234,7 +234,7 @@ files:
234
234
  - spec/func_tests/client_spec.rb
235
235
  - spec/func_tests/job_spec.rb
236
236
  - spec/func_tests/node_spec.rb
237
- - spec/func_tests/plugin_spec.rb.pending
237
+ - spec/func_tests/plugin_spec.rb
238
238
  - spec/func_tests/spec_helper.rb
239
239
  - spec/func_tests/system_spec.rb
240
240
  - spec/func_tests/user_spec.rb
@@ -271,10 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
271
271
  requirements:
272
272
  - - ! '>='
273
273
  - !ruby/object:Gem::Version
274
- version: '0'
275
- segments:
276
- - 0
277
- hash: -755549316541829445
274
+ version: 1.9.2
278
275
  required_rubygems_version: !ruby/object:Gem::Requirement
279
276
  none: false
280
277
  requirements: