jenkins2-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +0 -0
- data/lib/jenkins2-api/client.rb +78 -0
- data/lib/jenkins2-api/version.rb +4 -0
- data/lib/jenkins2-api.rb +2 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db1b6afbb7366e426d3c28baace37f5f52d06a39
|
4
|
+
data.tar.gz: f3ae3a37d294dc1d153cb941fd4efa89113128c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00350209e9c82864c1f2f3d04a60021599de65cf5d183b4be36c3efeeb62bdad9884c851f69924fccc13e7079d6406b12677eca381de157ca8e4b7f43a885d06
|
7
|
+
data.tar.gz: 10dfe56f5fd4359d7b409526d3b350c6293a0950f102f38507bdbd174e257b1502d1dc00ca38aecc7aebce73f4a5b81c24978fdf3ad5870a88a6c45b26d54e13
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (C) 2017 by Balazs Nadasdi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Jenkins2API
|
5
|
+
class Client
|
6
|
+
def initialize(**options)
|
7
|
+
@server = options[:server] || 'http://127.0.0.1/'
|
8
|
+
@username = options[:username]
|
9
|
+
@password = options[:password]
|
10
|
+
|
11
|
+
if @username && !@password
|
12
|
+
raise ArgumentError, "If username is provided, password is required"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def latest_build_for(name)
|
17
|
+
api_request(:get, "/job/#{name}/lastBuild")
|
18
|
+
end
|
19
|
+
|
20
|
+
def list_jobs
|
21
|
+
api_request(:get, "")['jobs']
|
22
|
+
end
|
23
|
+
|
24
|
+
def nodes
|
25
|
+
api_request(:get, "/computer")
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_full_log_lines(name, build_id)
|
29
|
+
api_request(:get, "/job/#{name}/#{build_id}/logText/progressiveText", :raw).split("\r\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_artifact_for(name, build_id, artifact)
|
33
|
+
api_request(:get, "/job/#{name}/#{build_id}/artifact/#{artifact['relativePath']}", :raw)
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_build_slave_name(name, build_id)
|
37
|
+
log = get_full_log_lines(name, build_id)
|
38
|
+
relevant_line = log.select { |line| line.match(/^Running on /) }.first
|
39
|
+
|
40
|
+
relevant_line.match(/^Running on (.*) in \//)[1]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def api_request(method, path, response_type = :json, **opts)
|
45
|
+
response_type = :json unless [:json, :raw].include?(response_type)
|
46
|
+
|
47
|
+
parts = [@server, URI.escape(path)]
|
48
|
+
parts << 'api/json' if response_type == :json
|
49
|
+
uri = URI(File.join(parts))
|
50
|
+
uri.query = URI.encode_www_form(opts)
|
51
|
+
|
52
|
+
req = case method
|
53
|
+
when :get then Net::HTTP::Get
|
54
|
+
when :post then Net::HTTP::Post
|
55
|
+
end.new(uri)
|
56
|
+
|
57
|
+
req.basic_auth @username, @password
|
58
|
+
yield req if block_given?
|
59
|
+
req.content_type ||= 'application/x-www-form-urlencoded'
|
60
|
+
response = Net::HTTP.start(req.uri.hostname, req.uri.port) { |http| http.request req }
|
61
|
+
|
62
|
+
case response
|
63
|
+
when Net::HTTPSuccess
|
64
|
+
if response_type == :json
|
65
|
+
JSON.parse(response.body)
|
66
|
+
else
|
67
|
+
response.body
|
68
|
+
end
|
69
|
+
when Net::HTTPRedirection
|
70
|
+
puts "Redirect: #{response['location']}"
|
71
|
+
response['location']
|
72
|
+
else
|
73
|
+
puts "Response: #{response.code}, #{response.body}"
|
74
|
+
response.value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/jenkins2-api.rb
ADDED
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenkins2-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Balazs Nadasdi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: API client for Jenkins 2.
|
14
|
+
email: balazs.nadasdi@cheppers.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- LICENSE
|
20
|
+
- README.md
|
21
|
+
- lib/jenkins2-api.rb
|
22
|
+
- lib/jenkins2-api/client.rb
|
23
|
+
- lib/jenkins2-api/version.rb
|
24
|
+
homepage: https://github.com/Yitsushi/jenkins2-api
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - "~>"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2.0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.4.5.1
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: API client for Jenkins 2.
|
48
|
+
test_files: []
|