jenkins_api_client 1.0.0.beta.2 → 1.0.0.beta.3

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.
@@ -1,26 +1,15 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
4
  - 2.0.0
4
5
  - 1.9.3
5
- - jruby-19mode
6
- - rbx-19mode
7
- matrix:
8
- allow_failures:
9
- - rvm: jruby-19mode
10
- - rvm: rbx-19mode
11
- before_install:
12
- - travis/setup.sh
13
6
 
14
7
  script:
15
8
  - bundle exec rake unit_tests
16
- - bundle exec rake func_tests
17
- - travis/setup_crumb.sh
18
- - bundle exec rake func_tests
9
+
19
10
  notifications:
20
11
  webhooks: https://www.buildheroes.com/api/projects/588c9dffdc8f0deff4d89d87bf370e8dba8a8a95/builds
21
- email: false
22
12
  irc:
23
- on_success: change
24
- on_failure: always
25
- channels:
26
- - "irc.freenode.org##jenkins-api-client"
13
+ channels: ["chat.freenode.net##jenkins-api-client"]
14
+ use_notice: true
15
+ skip_join: true
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "jenkins_api_client"
8
- s.version = "1.0.0.beta.2"
8
+ s.version = "1.0.0.beta.3"
9
9
 
10
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-12-18"
12
+ s.date = "2014-01-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"]
@@ -69,7 +69,7 @@ module JenkinsApi
69
69
  #
70
70
  # @option args [String] :server_ip the IP address of the Jenkins CI server
71
71
  # @option args [String] :server_port the port on which the Jenkins listens
72
- # @option args [String] :server_url the full URL address of the Jenkins CI server (http/https)
72
+ # @option args [String] :server_url the full URL address of the Jenkins CI server (http/https). This can include username/password. :username/:password options will override any user/pass value in the URL
73
73
  # @option args [String] :username the username used for connecting to the server (optional)
74
74
  # @option args [String] :password the password or API Key for connecting to the CI server (optional)
75
75
  # @option args [String] :password_base64 the password with base64 encoded format for connecting to the CI
@@ -105,6 +105,20 @@ module JenkinsApi
105
105
  " to Jenkins"
106
106
  end
107
107
 
108
+ # Get info from the server_url, if we got one
109
+ if @server_url
110
+ server_uri = URI.parse(@server_url)
111
+ @server_ip = server_uri.host
112
+ @server_port = server_uri.port
113
+ @ssl = server_uri.scheme == "https"
114
+ @jenkins_path = server_uri.path
115
+
116
+ # read username and password from the URL
117
+ # only set if @username and @password are not already set via explicit options
118
+ @username ||= server_uri.user
119
+ @password ||= server_uri.password
120
+ end
121
+
108
122
  # Username/password are optional as some jenkins servers do not require
109
123
  # authentication
110
124
  if @username && !(@password || @password_base64)
@@ -115,15 +129,6 @@ module JenkinsApi
115
129
  " both left nil"
116
130
  end
117
131
 
118
- # Get info from the server_url, if we got one
119
- if @server_url
120
- server_uri = URI.parse(@server_url)
121
- @server_ip = server_uri.host
122
- @server_port = server_uri.port
123
- @ssl = server_uri.scheme == "https"
124
- @jenkins_path = server_uri.path
125
- end
126
-
127
132
  @jenkins_path ||= ""
128
133
  @jenkins_path.gsub!(/\/$/,"") # remove trailing slash if there is one
129
134
  @server_port = DEFAULT_SERVER_PORT unless @server_port
@@ -532,6 +537,22 @@ module JenkinsApi
532
537
  response["Date"]
533
538
  end
534
539
 
540
+ # Executes the provided groovy script on the Jenkins CI server
541
+ #
542
+ # @param [String] script_text The text of the groovy script to execute
543
+ #
544
+ # @return [String] The output of the executed groovy script
545
+ #
546
+ def exec_script(script_text)
547
+ url = URI.escape("#{@jenkins_path}/scriptText")
548
+ request = Net::HTTP::Post.new("#{url}")
549
+ request.form_data = { 'script' => script_text }
550
+ @logger.info "POST #{url}"
551
+
552
+ response = make_http_request(request)
553
+ handle_exception(response, 'body')
554
+ end
555
+
535
556
  # Execute the Jenkins CLI
536
557
  #
537
558
  # @param command [String] command name
@@ -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 = 'beta.2'
32
+ PRE = 'beta.3'
33
33
  # Version String of Jenkins API Client.
34
34
  VERSION = [MAJOR, MINOR, TINY, PRE].compact.join('.')
35
35
  end
@@ -65,6 +65,12 @@ describe JenkinsApi::Client do
65
65
  @client.get_hudson_version.class.should == String
66
66
  end
67
67
  end
68
+
69
+ describe "#exec_script" do
70
+ it "Should execute the provided groovy script" do
71
+ @client.exec_script('println("hi")').should == "hi\n"
72
+ end
73
+ end
68
74
  end
69
75
 
70
76
  describe "SubClassAccessorMethods" do
@@ -49,6 +49,26 @@ describe JenkinsApi::Client do
49
49
  ).not_to raise_error
50
50
  end
51
51
 
52
+ it "initializes the username and password from server_url" do
53
+ client = JenkinsApi::Client.new(
54
+ :server_url => 'http://someuser:asdf@localhost'
55
+ )
56
+
57
+ client.instance_variable_get('@username').should == 'someuser'
58
+ client.instance_variable_get('@password').should == 'asdf'
59
+ end
60
+
61
+ it "uses explicit username, password over one in the server_url" do
62
+ client = JenkinsApi::Client.new(
63
+ :server_url => 'http://someuser:asdf@localhost',
64
+ :username => 'otheruser',
65
+ :password => '1234'
66
+ )
67
+
68
+ client.instance_variable_get('@username').should == 'otheruser'
69
+ client.instance_variable_get('@password').should == '1234'
70
+ end
71
+
52
72
  it "initializes with proxy args without exception" do
53
73
  expect(
54
74
  lambda do
@@ -198,6 +218,13 @@ describe JenkinsApi::Client do
198
218
  end
199
219
  end
200
220
 
221
+ describe "#exec_script" do
222
+ it "is defined and should accept script to execute" do
223
+ @client.respond_to?(:exec_script).should be_true
224
+ @client.method(:exec_script).parameters.size.should == 1
225
+ end
226
+ end
227
+
201
228
  describe "#exec_cli" do
202
229
  it "is defined and should execute the CLI" do
203
230
  @client.respond_to?(:exec_cli).should be_true
@@ -85,7 +85,7 @@ __USERLIST
85
85
  @client.should_receive(:logger).and_return(mock_logger)
86
86
  @client.should_receive(:timeout).and_return(mock_timeout)
87
87
  @client.stub(:api_get_request).with('/asynchPeople').and_return(PEOPLE_JSON)
88
- @client.stub(:api_get_request).with('/user/Fred Flintstone').and_return(FRED_JSON)
88
+ @client.stub(:api_get_request).with('/user/Fred%20Flintstone').and_return(FRED_JSON)
89
89
  @client.stub(:api_get_request).with('/user/fred').and_return(FRED_JSON)
90
90
  @client.stub(:api_get_request).with('/user/wilma').and_return(WILMA_JSON)
91
91
  @user = JenkinsApi::Client::User.new(@client)
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.2
4
+ version: 1.0.0.beta.3
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-12-18 00:00:00.000000000 Z
12
+ date: 2014-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri