jenkins_api_client 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,19 +21,26 @@
21
21
  #
22
22
 
23
23
  module JenkinsApi
24
+ # This module contains classes that define exceptions for various catories.
24
25
  module Exceptions
26
+ # This is the base class for Exceptions that is inherited from
27
+ # RuntimeError.
25
28
  class ApiException < RuntimeError
26
29
  def initialize(message = "")
27
30
  super("Error: #{message}")
28
31
  end
29
32
  end
30
33
 
34
+ # This exception class handles cases where invalid credentials are provided
35
+ # to connect to the Jenkins
31
36
  class UnautherizedException < ApiException
32
37
  def initialize(message = "")
33
38
  super("Invalid credentials are provided. #{message}")
34
39
  end
35
40
  end
36
41
 
42
+ # This exception class handles cases where a requested page is not found on
43
+ # the Jenkins API
37
44
  class NotFoundException < ApiException
38
45
  def initialize(message = "")
39
46
  super("Requested component is not found on the Jenkins CI server." +
@@ -41,6 +48,8 @@ module JenkinsApi
41
48
  end
42
49
  end
43
50
 
51
+ # This exception class handles cases where the Jenkins API returns with a
52
+ # 500 Internel Server Error
44
53
  class InternelServerErrorException < ApiException
45
54
  def initialize(message = "")
46
55
  super("Internel Server Error. Perhaps the in-memory configuration of" +
@@ -49,5 +58,12 @@ module JenkinsApi
49
58
  )
50
59
  end
51
60
  end
61
+
62
+ # Exception occurred while running java CLI commands
63
+ class CLIException < ApiException
64
+ def initialize(message = "")
65
+ super("Execute CLI Error. #{message}")
66
+ end
67
+ end
52
68
  end
53
69
  end
@@ -22,6 +22,8 @@
22
22
 
23
23
  module JenkinsApi
24
24
  class Client
25
+ # This class communicates with the Jenkins "/job" API to obtain details
26
+ # about jobs, creating, deleting, building, and various other operations.
25
27
  class Job
26
28
 
27
29
  # Initialize the Job object and store the reference to Client object
@@ -211,6 +213,7 @@ module JenkinsApi
211
213
  # @option params [String] :notification_email Email address to send
212
214
  # @option params [TrueClass|FalseClass] :notification_email_for_every_unstable
213
215
  # Send email notification email for every unstable build
216
+ #
214
217
  def add_email_notification(params)
215
218
  raise "No job name specified" unless params[:name]
216
219
  raise "No email address specified" unless params[:notification_email]
@@ -357,7 +360,8 @@ module JenkinsApi
357
360
  end
358
361
  get_msg = "/job/#{job_name}/#{build_num}/logText/progressive#{mode}?"
359
362
  get_msg << "start=#{start}"
360
- api_response = @client.api_get_request(get_msg, nil, nil)
363
+ raw_response = true
364
+ api_response = @client.api_get_request(get_msg, nil, nil, raw_response)
361
365
  #puts "Response: #{api_response.header['x-more-data']}"
362
366
  response = {}
363
367
  response['output'] = api_response.body
@@ -22,6 +22,8 @@
22
22
 
23
23
  module JenkinsApi
24
24
  class Client
25
+ # This class communicates with Jenkins "/computer" API to obtain details
26
+ # about nodes or slaves connected to the Jenkins.
25
27
  class Node
26
28
 
27
29
  # General attributes of a node.
@@ -24,6 +24,8 @@ require 'timeout'
24
24
 
25
25
  module JenkinsApi
26
26
  class Client
27
+ # This class is used to communicate with Jenkins and performing some admin
28
+ # level operations such as restarting and reloading Jenkins.
27
29
  class System
28
30
 
29
31
  # Initializes a new System object.
@@ -22,10 +22,15 @@
22
22
 
23
23
  module JenkinsApi
24
24
  class Client
25
+ # Major version of the gem
25
26
  MAJOR = 0
26
- MINOR = 9
27
- TINY = 1
27
+ # Minor version of the gem
28
+ MINOR = 10
29
+ # Tiny version of the gem used for patches
30
+ TINY = 0
31
+ # Used for pre-releases
28
32
  PRE = nil
33
+ # Version String of Jenkins API Client.
29
34
  VERSION = [MAJOR, MINOR, TINY, PRE].compact.join('.')
30
35
  end
31
36
  end
@@ -22,6 +22,9 @@
22
22
 
23
23
  module JenkinsApi
24
24
  class Client
25
+ # This class communicates with Jenkins "/view" API and used to create,
26
+ # delete, update, and various other operations permitted on the Jenkins
27
+ # API.
25
28
  class View
26
29
 
27
30
  # Initializes a new view object
@@ -7,8 +7,46 @@ require 'jenkins_api_client'
7
7
  require 'yaml'
8
8
  require 'irb'
9
9
 
10
+ def prompt_for_username
11
+ get_from_stdin("Username: ", false)
12
+ end
13
+
14
+ def prompt_for_password
15
+ get_from_stdin("Password: ", true)
16
+ end
17
+
18
+ def get_from_stdin(prompt, mask = false)
19
+ $stdout.write(prompt)
20
+
21
+ begin
22
+ Kernel::system "stty -echo" if mask == true
23
+ ret = gets.chomp!
24
+ ensure
25
+ if mask == true
26
+ Kernel::system "stty echo"
27
+ puts ""
28
+ end
29
+ end
30
+
31
+ ret
32
+ end
33
+
34
+ if ARGV.empty?
35
+ config_file = '~/.jenkins_api_client/login.yml'
36
+ else
37
+ config_file = ARGV.shift
38
+ end
39
+
10
40
  begin
11
- @client = JenkinsApi::Client.new(YAML.load_file(File.expand_path('~/.jenkins_api_client/login.yml', __FILE__)))
41
+ client_opts = YAML.load_file(File.expand_path(config_file))
42
+ unless client_opts.has_key?(:username)
43
+ client_opts[:username] = prompt_for_username()
44
+ end
45
+ unless client_opts.has_key?(:password) or client_opts.has_key?(:password_base64)
46
+ client_opts[:password] = prompt_for_password()
47
+ end
48
+
49
+ @client = JenkinsApi::Client.new(client_opts)
12
50
  puts "logged-in to the Jenkins API, use the '@client' variable to use the client"
13
51
  end
14
52
 
@@ -24,6 +24,21 @@ describe JenkinsApi::Client do
24
24
  end
25
25
  ).not_to raise_error
26
26
  end
27
+
28
+ it "initializes with proxy args without exception" do
29
+ expect(
30
+ lambda do
31
+ JenkinsApi::Client.new(
32
+ :server_ip => '127.0.0.1',
33
+ :server_port => 8080,
34
+ :username => 'username',
35
+ :password => 'password',
36
+ :proxy_ip => '127.0.0.1',
37
+ :proxy_port => 8081
38
+ )
39
+ end
40
+ ).not_to raise_error
41
+ end
27
42
  end
28
43
 
29
44
  describe "#SubClassAccessorMethods" do
@@ -187,6 +202,14 @@ describe JenkinsApi::Client do
187
202
  ).not_to raise_error(NoMethodError)
188
203
  end
189
204
  end
205
+
206
+ describe "#exec_cli" do
207
+ it "is defined and should execute the CLI" do
208
+ expect(
209
+ lambda { @client.exec_cli("version") }
210
+ ).not_to raise_error(NoMethodError)
211
+ end
212
+ end
190
213
  end
191
214
  end
192
215
 
@@ -230,6 +253,34 @@ describe JenkinsApi::Client do
230
253
  end
231
254
  ).to raise_error
232
255
  end
256
+
257
+ it "Should fail if proxy_ip is specified but proxy_port is not" do
258
+ expect(
259
+ lambda do
260
+ JenkinsApi::Client.new({
261
+ :bogus => '127.0.0.1',
262
+ :server_port => 8080,
263
+ :username => 'username',
264
+ :password => 'password',
265
+ :proxy_ip => '127.0.0.1',
266
+ })
267
+ end
268
+ ).to raise_error
269
+ end
270
+
271
+ it "Should fail if proxy_port is specified but proxy_ip is not" do
272
+ expect(
273
+ lambda do
274
+ JenkinsApi::Client.new({
275
+ :bogus => '127.0.0.1',
276
+ :server_port => 8080,
277
+ :username => 'username',
278
+ :password => 'password',
279
+ :proxy_port => 8081,
280
+ })
281
+ end
282
+ ).to raise_error
283
+ end
233
284
  end
234
285
  end
235
286
  end
@@ -197,8 +197,10 @@ describe JenkinsApi::Client::Job do
197
197
 
198
198
  describe "#get_console_output" do
199
199
  it "accepts the job name and the obtains the console output" do
200
- @client.should_receive(:api_get_request).and_return(
201
- Net::HTTP.get_response(URI('http://example.com/index.html')))
200
+ msg = "/job/test_job/1/logText/progressiveText?start=0"
201
+ @client.should_receive(:api_get_request).
202
+ with(msg, nil, nil, true).
203
+ and_return(Net::HTTP.get_response(URI('http://example.com/index.html')))
202
204
  @job.get_console_output('test_job', 1, 0, 'text')
203
205
  end
204
206
 
metadata CHANGED
@@ -1,138 +1,172 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jenkins_api_client
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 9
8
- - 1
9
- version: 0.9.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Kannan Manickam
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2013-04-02 00:00:00 -07:00
18
- default_executable: jenkinscli
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- prerelease: false
22
- type: :runtime
12
+ date: 2013-04-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
23
15
  name: nokogiri
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
31
- requirement: *id001
32
- - !ruby/object:Gem::Dependency
33
- prerelease: false
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
34
22
  type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
35
31
  name: thor
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- - 16
43
- - 0
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
44
37
  version: 0.16.0
45
- requirement: *id002
46
- - !ruby/object:Gem::Dependency
47
- prerelease: false
48
38
  type: :runtime
49
- name: json
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- version: "0"
57
- requirement: *id003
58
- - !ruby/object:Gem::Dependency
59
39
  prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.16.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
60
54
  type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
61
63
  name: terminal-table
62
- version_requirements: &id004 !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- segments:
67
- - 1
68
- - 4
69
- - 0
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
70
69
  version: 1.4.0
71
- requirement: *id004
72
- - !ruby/object:Gem::Dependency
70
+ type: :runtime
73
71
  prerelease: false
74
- type: :development
75
- name: bundler
76
- version_requirements: &id005 !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- segments:
81
- - 1
82
- - 0
83
- version: "1.0"
84
- requirement: *id005
85
- - !ruby/object:Gem::Dependency
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.4.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: mixlib-shellout
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.1.0
86
+ type: :runtime
86
87
  prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.1.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: bundler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '1.0'
87
102
  type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '1.0'
110
+ - !ruby/object:Gem::Dependency
88
111
  name: jeweler
89
- version_requirements: &id006 !ruby/object:Gem::Requirement
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- segments:
94
- - 1
95
- - 6
96
- - 4
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
97
117
  version: 1.6.4
98
- requirement: *id006
99
- - !ruby/object:Gem::Dependency
100
- prerelease: false
101
118
  type: :development
102
- name: simplecov
103
- version_requirements: &id007 !ruby/object:Gem::Requirement
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- segments:
108
- - 0
109
- version: "0"
110
- requirement: *id007
111
- - !ruby/object:Gem::Dependency
112
119
  prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 1.6.4
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
113
134
  type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
114
143
  name: rspec
115
- version_requirements: &id008 !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- segments:
120
- - 0
121
- version: "0"
122
- requirement: *id008
123
- description: |-
124
-
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: ! '
159
+
125
160
  This is a simple and easy-to-use Jenkins Api client with features focused on
126
- automating Job configuration programaticaly and so forth
127
- email:
161
+
162
+ automating Job configuration programaticaly and so forth'
163
+ email:
128
164
  - arangamani.kannan@gmail.com
129
- executables:
165
+ executables:
130
166
  - jenkinscli
131
167
  extensions: []
132
-
133
168
  extra_rdoc_files: []
134
-
135
- files:
169
+ files:
136
170
  - .gitignore
137
171
  - .jenkins.yml
138
172
  - .travis.yml
@@ -143,6 +177,8 @@ files:
143
177
  - Rakefile
144
178
  - bin/jenkinscli
145
179
  - config/login.yml.example
180
+ - java_deps/jenkins-cli.jar
181
+ - jenkins_api_client.gemspec
146
182
  - lib/jenkins_api_client.rb
147
183
  - lib/jenkins_api_client/build_queue.rb
148
184
  - lib/jenkins_api_client/cli/base.rb
@@ -173,35 +209,28 @@ files:
173
209
  - spec/unit_tests/spec_helper.rb
174
210
  - spec/unit_tests/system_spec.rb
175
211
  - spec/unit_tests/view_spec.rb
176
- has_rdoc: true
177
212
  homepage: https://github.com/arangamani/jenkins_api_client
178
213
  licenses: []
179
-
180
214
  post_install_message:
181
215
  rdoc_options: []
182
-
183
- require_paths:
216
+ require_paths:
184
217
  - lib
185
- required_ruby_version: !ruby/object:Gem::Requirement
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- segments:
190
- - 0
191
- version: "0"
192
- required_rubygems_version: !ruby/object:Gem::Requirement
193
- requirements:
194
- - - ">="
195
- - !ruby/object:Gem::Version
196
- segments:
197
- - 0
198
- version: "0"
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ! '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
199
230
  requirements: []
200
-
201
231
  rubyforge_project:
202
- rubygems_version: 1.3.6
232
+ rubygems_version: 1.8.23
203
233
  signing_key:
204
234
  specification_version: 3
205
235
  summary: Jenkins JSON API Client
206
236
  test_files: []
207
-