jenkins2-api 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/bin/jenkins2api +3 -0
- data/lib/client.rb +21 -0
- data/lib/commands/build.rb +3 -0
- data/lib/commands/job.rb +2 -0
- data/lib/commands/node.rb +5 -0
- data/lib/endpoint.rb +9 -0
- data/lib/endpoints/artifact.rb +18 -5
- data/lib/endpoints/build.rb +32 -5
- data/lib/endpoints/job.rb +12 -5
- data/lib/endpoints/node.rb +8 -5
- data/lib/thor_command.rb +5 -0
- data/lib/version.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6bfbc056dbe1bc9f82b4f9178e5f7892e06eee8
|
4
|
+
data.tar.gz: 6c8d9cc4ebb65a8ce2b0498734858b2dfd0b7740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 627027afdbe1cb6d91f7b2a0818d2b272cf375f14ee54ef94bf2ed50481dd7c49f879efa5dbe57e77bc92d417b9ab01cc4c454b5934126a5e787b7f2ee51c067
|
7
|
+
data.tar.gz: 00e6d6f5c358c5664d05556224f6cdb1d208791609d15a6f63f1466924a44f4f035a836170a6a1cfe0c81e0f768a42cfbd187c3cadd3a5c57930c232d256a9e9
|
data/bin/jenkins2api
CHANGED
@@ -4,11 +4,14 @@ require 'thor'
|
|
4
4
|
require 'jenkins2-api'
|
5
5
|
|
6
6
|
module Jenkins2API
|
7
|
+
# CLI wrapper under Jenkins2API
|
7
8
|
module CLI
|
9
|
+
# Base class for Thor with registered modules and version info
|
8
10
|
class Jenkins2 < Thor
|
9
11
|
map %w[--version -v] => :__print_version
|
10
12
|
|
11
13
|
desc "--version, -v", "print the version"
|
14
|
+
# Prints the current version number
|
12
15
|
def __print_version
|
13
16
|
puts Jenkins2API::VERSION
|
14
17
|
end
|
data/lib/client.rb
CHANGED
@@ -6,8 +6,18 @@ require_relative './endpoints/build'
|
|
6
6
|
require_relative './endpoints/job'
|
7
7
|
require_relative './endpoints/node'
|
8
8
|
|
9
|
+
# Jenkins2API codebase wrapper
|
9
10
|
module Jenkins2API
|
11
|
+
# Basically the only public class to call Jenkins2 API nedpoints
|
10
12
|
class Client
|
13
|
+
# Save Jenkins credentials and server path
|
14
|
+
#
|
15
|
+
# ==== Options:
|
16
|
+
# +server+:: Server path (e.g.: https://jenkins.example.com/)
|
17
|
+
# +username+:: Username for Jenkins
|
18
|
+
# +password+:: Password or API Token for Jenkins
|
19
|
+
# Throws an +ArgumentError+ if username is specified
|
20
|
+
# but password is empty
|
11
21
|
def initialize(**options)
|
12
22
|
@server = options[:server] || 'http://127.0.0.1/'
|
13
23
|
@username = options[:username]
|
@@ -18,22 +28,33 @@ module Jenkins2API
|
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
31
|
+
# Job related endpoints. Creates new +Jenkins2API::Job+ instance
|
21
32
|
def job
|
22
33
|
@job ||= Job.new(self)
|
23
34
|
end
|
24
35
|
|
36
|
+
# Build related endpoints. Creates new +Jenkins2API::Build+ instance
|
25
37
|
def build
|
26
38
|
@build ||= Build.new(self)
|
27
39
|
end
|
28
40
|
|
41
|
+
# Artifact related endpoints. Creates new +Jenkins2API::Artifact+ instance
|
29
42
|
def artifact
|
30
43
|
@artifact ||= Artifact.new(self)
|
31
44
|
end
|
32
45
|
|
46
|
+
# Node/Computer related endpoints. Creates new +Jenkins2API::Node+ instance
|
33
47
|
def node
|
34
48
|
@node ||= Node.new(self)
|
35
49
|
end
|
36
50
|
|
51
|
+
# Creates and calls an API endpoint.
|
52
|
+
#
|
53
|
+
# ==== Params:
|
54
|
+
# +method+:: +:post+ or +:get+
|
55
|
+
# +path+:: Path to the Jenkins resource (e.g.: +/job/my-job/+)
|
56
|
+
# +response_type+:: +:json+ or +:raw+
|
57
|
+
# +opts+:: sym options to pass to the endpoint. Applicable only if +:post+
|
37
58
|
def api_request(method, path, response_type = :json, **opts)
|
38
59
|
response_type = :json unless [:json, :raw].include?(response_type)
|
39
60
|
|
data/lib/commands/build.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'thor'
|
2
2
|
|
3
3
|
module Jenkins2API
|
4
|
+
# Command module wraps all the cli commands
|
4
5
|
module Command
|
6
|
+
# Contains all the commands under +build+ namespace
|
5
7
|
class Build < Jenkins2API::ThorCommand
|
6
8
|
desc 'slave-name JOB_NAME BUILD_ID', 'Get Node name where a specific build was running'
|
7
9
|
method_option :ec2id, :default => false, :type => :boolean
|
10
|
+
# Displays the name of the slave where the build was executed
|
8
11
|
def slave_name(name, build_id)
|
9
12
|
slave_name = client.build.slave_name(name, build_id)
|
10
13
|
slave_name = slave_name.match(/(i-[0-9a-zA-Z]+)/).captures.first if options[:ec2id]
|
data/lib/commands/job.rb
CHANGED
data/lib/commands/node.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'thor'
|
2
2
|
|
3
3
|
module Jenkins2API
|
4
|
+
# Command module wraps all the cli commands
|
4
5
|
module Command
|
6
|
+
# Contains all the commands under +node+ namespace
|
5
7
|
class Node < Jenkins2API::ThorCommand
|
8
|
+
|
6
9
|
desc :all, "List all nodes"
|
10
|
+
# List all available nodes
|
7
11
|
def all
|
8
12
|
nodes = client.node.all
|
9
13
|
nodes['computer'].each do |computer|
|
@@ -14,6 +18,7 @@ module Jenkins2API
|
|
14
18
|
end
|
15
19
|
|
16
20
|
desc :slaves, "List all slave nodes"
|
21
|
+
# List all avilable slaves
|
17
22
|
def slaves
|
18
23
|
nodes = client.node.all
|
19
24
|
nodes['computer'].each do |computer|
|
data/lib/endpoint.rb
ADDED
data/lib/endpoints/artifact.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
|
-
|
2
|
-
class Artifact
|
3
|
-
def initialize(client)
|
4
|
-
@client = client
|
5
|
-
end
|
1
|
+
require_relative '../endpoint'
|
6
2
|
|
3
|
+
module Jenkins2API
|
4
|
+
# This class contains all the calls to reach
|
5
|
+
# Jenkins2 and obtain Artifact data
|
6
|
+
class Artifact < Endpoint
|
7
|
+
# Returns a list of all artifacts for a specific build
|
8
|
+
#
|
9
|
+
# Params:
|
10
|
+
# +name+:: Job name
|
11
|
+
# +build_id+:: ID of the build
|
7
12
|
def all(name, build_id)
|
8
13
|
@client.build.get(name)['artifacts']
|
9
14
|
end
|
10
15
|
|
16
|
+
# Download a specific artifact.
|
17
|
+
#
|
18
|
+
# Params:
|
19
|
+
# +name+:: Job name
|
20
|
+
# +build_id+:: ID of the build
|
21
|
+
# +artifact+:: artifact +Hash+. this function uses only the +relativePath+ property
|
22
|
+
#
|
23
|
+
# Returns with the content of the artifact
|
11
24
|
def get(name, build_id, artifact)
|
12
25
|
@client.api_request(:get, "/job/#{name}/#{build_id}/artifact/#{artifact['relativePath']}", :raw)
|
13
26
|
end
|
data/lib/endpoints/build.rb
CHANGED
@@ -1,25 +1,52 @@
|
|
1
|
-
|
2
|
-
class Build
|
3
|
-
def initialize(client)
|
4
|
-
@client = client
|
5
|
-
end
|
1
|
+
require_relative '../endpoint'
|
6
2
|
|
3
|
+
module Jenkins2API
|
4
|
+
# This class contains all the calls to reach
|
5
|
+
# Jenkins2 and obtain Build data
|
6
|
+
class Build < Endpoint
|
7
|
+
# Get a specific build
|
8
|
+
#
|
9
|
+
# ==== Params:
|
10
|
+
# +job_name+:: Name of the Job
|
11
|
+
# +build_id+:: ID of the build
|
7
12
|
def get(job_name, build_id)
|
8
13
|
@client.api_request(:get, "/job/#{job_name}/#{build_id}")
|
9
14
|
end
|
10
15
|
|
16
|
+
# Get the latest build
|
17
|
+
#
|
18
|
+
# ==== Params:
|
19
|
+
# +job_name+:: Name of the Job
|
11
20
|
def latest(name)
|
12
21
|
@client.api_request(:get, "/job/#{name}/lastBuild")
|
13
22
|
end
|
14
23
|
|
24
|
+
# Get test report for a specific build
|
25
|
+
#
|
26
|
+
# ==== Params:
|
27
|
+
# +name+:: Name of the Job
|
28
|
+
# +build_id+:: ID of the build
|
15
29
|
def test_results(name, build_id)
|
16
30
|
@client.api_request(:get, "/job/#{name}/#{build_id}/testReport")
|
17
31
|
end
|
18
32
|
|
33
|
+
# Get +console log+ for a specific build as text
|
34
|
+
#
|
35
|
+
# ==== Params:
|
36
|
+
# +job_name+:: Name of the Job
|
37
|
+
# +build_id+:: ID of the build
|
38
|
+
#
|
39
|
+
# Return an array of strings.
|
40
|
+
# Each item in that array is a line from the log
|
19
41
|
def logtext_lines(name, build_id)
|
20
42
|
@client.api_request(:get, "/job/#{name}/#{build_id}/logText/progressiveText", :raw).split("\r\n")
|
21
43
|
end
|
22
44
|
|
45
|
+
# Get the name of the slave where the build was executed
|
46
|
+
#
|
47
|
+
# ==== Params:
|
48
|
+
# +name+:: Name of the Job
|
49
|
+
# +build_id+:: ID of the build
|
23
50
|
def slave_name(name, build_id)
|
24
51
|
log = logtext_lines(name, build_id)
|
25
52
|
relevant_line = log.select { |line| line.match(/^Running on /) }.first
|
data/lib/endpoints/job.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
-
|
2
|
-
class Job
|
3
|
-
def initialize(client)
|
4
|
-
@client = client
|
5
|
-
end
|
1
|
+
require_relative '../endpoint'
|
6
2
|
|
3
|
+
module Jenkins2API
|
4
|
+
# This class contains all the calls to reach
|
5
|
+
# Jenkins2 and obtain Build data
|
6
|
+
class Job < Endpoint
|
7
|
+
# Lists all available jobs
|
7
8
|
def list
|
8
9
|
@client.api_request(:get, "")['jobs']
|
9
10
|
end
|
10
11
|
|
12
|
+
# Get all available builds for a specific job
|
13
|
+
#
|
14
|
+
# ==== Params:
|
15
|
+
# +name+:: Name of the Job
|
16
|
+
#
|
17
|
+
# Returns with an array of builds
|
11
18
|
def builds(name)
|
12
19
|
@client.api_request(:get, "/job/#{name}")['builds']
|
13
20
|
end
|
data/lib/endpoints/node.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
2
|
-
class Node
|
3
|
-
def initialize(client)
|
4
|
-
@client = client
|
5
|
-
end
|
1
|
+
require_relative '../endpoint'
|
6
2
|
|
3
|
+
module Jenkins2API
|
4
|
+
# This class contains all the calls to reach
|
5
|
+
# Jenkins2 and obtain Computer data
|
6
|
+
class Node < Endpoint
|
7
|
+
# List all available Computer
|
8
|
+
#
|
9
|
+
# Returns with slaves and masters also
|
7
10
|
def all
|
8
11
|
@client.api_request(:get, "/computer")
|
9
12
|
end
|
data/lib/thor_command.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'thor'
|
2
2
|
|
3
|
+
# Jenkins2API codebase wrapper
|
3
4
|
module Jenkins2API
|
5
|
+
# Wrapper class for commands. Checks if credentials are passed or not
|
6
|
+
# and creates a new +Jenkins2API::Client+ instance for commands.
|
4
7
|
class ThorCommand < Thor
|
5
8
|
class_option :password, :desc => "Password", :aliases => "-p", :required => false
|
6
9
|
class_option :username, :desc => "Username", :aliases => "-u", :required => false
|
7
10
|
class_option :server, :desc => "Server path", :aliases => "-s", :required => false
|
8
11
|
|
9
12
|
private
|
13
|
+
# Get or create a new client
|
10
14
|
def client
|
11
15
|
check_option(:server, 'JENKINS_SERVER')
|
12
16
|
check_option(:username, 'JENKINS_USERNAME')
|
@@ -19,6 +23,7 @@ module Jenkins2API
|
|
19
23
|
)
|
20
24
|
end
|
21
25
|
|
26
|
+
# Check option or environment variable content
|
22
27
|
def check_option(name, env_name)
|
23
28
|
options[name] ||= ENV.fetch(env_name, '')
|
24
29
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins2-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Balazs Nadasdi
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/commands/build.rb
|
39
39
|
- lib/commands/job.rb
|
40
40
|
- lib/commands/node.rb
|
41
|
+
- lib/endpoint.rb
|
41
42
|
- lib/endpoints/artifact.rb
|
42
43
|
- lib/endpoints/build.rb
|
43
44
|
- lib/endpoints/job.rb
|
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
version: '0'
|
66
67
|
requirements: []
|
67
68
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.6.11
|
69
70
|
signing_key:
|
70
71
|
specification_version: 4
|
71
72
|
summary: API client for Jenkins 2.
|