jenkins2 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/jenkins2/client.rb +27 -9
- data/lib/jenkins2/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89eb3788e74b3dca921bb2f0cbe47532563fda46
|
4
|
+
data.tar.gz: e1f46c1ccabb5c259cc650dc9cdf1041ca627429
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd24ec55acd234fa995b76b35a826a67058fc59df0f4cec26319780bcfce28547f955f39ebc4b598a365c0a06429fca2598868eb8b2198fceea33ae01e5f5e55
|
7
|
+
data.tar.gz: 9743457399f767bba6cea77a0e7d61bafd9207ca5da14fac17891f6230256984bc6c545f5236a48c80008f7000339e01a5cf2770ca2f950714c0ce58fe7cd0a1
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.1.0](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v0.1.0) (2017-10-11)
|
4
|
+
|
5
|
+
### Enhancements
|
6
|
+
|
7
|
+
- Support Crumbs
|
8
|
+
- Can forcefully restart Jenkins
|
9
|
+
|
3
10
|
## [v0.0.2](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v0.0.2) (2016-10-25)
|
11
|
+
|
4
12
|
### Enhancements
|
13
|
+
|
5
14
|
- Hopefully this gem is now usable
|
6
15
|
- Get Jenkins version
|
7
16
|
- Prepare for / cancel Jenkins shutdown
|
data/lib/jenkins2/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'openssl'
|
2
3
|
require 'json'
|
3
4
|
|
4
5
|
require_relative 'log'
|
@@ -23,6 +24,7 @@ module Jenkins2
|
|
23
24
|
@server = args[:server]
|
24
25
|
@user = args[:user]
|
25
26
|
@key = args[:key]
|
27
|
+
@crumb = nil
|
26
28
|
end
|
27
29
|
|
28
30
|
# Returns Jenkins version
|
@@ -36,6 +38,12 @@ module Jenkins2
|
|
36
38
|
api_request( :post, '/quietDown' )
|
37
39
|
end
|
38
40
|
|
41
|
+
# Forcefully restart Jenkins NOW!
|
42
|
+
# Parameters are ignored
|
43
|
+
def restart!( **args )
|
44
|
+
api_request( :post, '/restart' )
|
45
|
+
end
|
46
|
+
|
39
47
|
# Cancels the effect of +prepare-for-shutdown+ command.
|
40
48
|
# Parameters are ignored
|
41
49
|
def cancel_shutdown( **args )
|
@@ -74,12 +82,28 @@ module Jenkins2
|
|
74
82
|
when :post then Net::HTTP::Post
|
75
83
|
end.new( URI File.join( @server, URI.escape( path ) ) )
|
76
84
|
Log.debug { "Request: #{method} #{req.uri}" }
|
77
|
-
req.basic_auth @user, @key
|
85
|
+
req.basic_auth @user, @key
|
78
86
|
yield req if block_given?
|
79
87
|
req.content_type ||= 'application/x-www-form-urlencoded'
|
80
88
|
Log.debug { "Request content_type: #{req.content_type}, body: #{req.body}" }
|
81
|
-
|
82
|
-
|
89
|
+
begin
|
90
|
+
req[@crumb["crumbRequestField"]] = @crumb["crumb"] if @crumb
|
91
|
+
response = Net::HTTP.start( req.uri.hostname, req.uri.port, use_ssl: req.uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE ) do |http|
|
92
|
+
http.request req
|
93
|
+
end
|
94
|
+
handle_response( response, reply_with )
|
95
|
+
rescue Net::HTTPServerException => e
|
96
|
+
if e.message == "403 \"No valid crumb was included in the request\""
|
97
|
+
update_crumbs
|
98
|
+
retry
|
99
|
+
else
|
100
|
+
raise
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def update_crumbs
|
106
|
+
@crumb = api_request( :get, '/crumbIssuer/api/json' )
|
83
107
|
end
|
84
108
|
|
85
109
|
def handle_response( response, reply_with )
|
@@ -94,16 +118,10 @@ module Jenkins2
|
|
94
118
|
when Net::HTTPRedirection
|
95
119
|
response['location']
|
96
120
|
when Net::HTTPClientError, Net::HTTPServerError
|
97
|
-
Log.error { "Response: #{response.code}, #{response.body}" }
|
98
121
|
response.value
|
99
122
|
else
|
100
|
-
Log.error { "Response: #{response.code}, #{response.body}" }
|
101
123
|
response.value
|
102
124
|
end
|
103
125
|
end
|
104
|
-
|
105
|
-
def credentials_provided?
|
106
|
-
@user and @key
|
107
|
-
end
|
108
126
|
end
|
109
127
|
end
|
data/lib/jenkins2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juri Timošin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-kitchen
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.17'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.17'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: kitchen-lxd
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.2'
|
83
111
|
description: Command line interface and API client for Jenkins 2. Allows manipulating
|
84
112
|
nodes, jobs, plugins, credentials. See README.md for details.
|
85
113
|
email: draco.ater@gmail.com
|
@@ -124,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
152
|
version: '0'
|
125
153
|
requirements: []
|
126
154
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.5.2
|
128
156
|
signing_key:
|
129
157
|
specification_version: 4
|
130
158
|
summary: Command line interface and API client for Jenkins 2.
|