SimpleJenkins 1.0.0
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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/lib/simple_jenkins.rb +12 -0
- data/lib/simple_jenkins/adapter.rb +91 -0
- data/lib/simple_jenkins/job.rb +101 -0
- data/lib/simple_jenkins/response.rb +14 -0
- data/lib/simple_jenkins/version.rb +3 -0
- data/lib/simple_jenkins/view.rb +13 -0
- data/simple_jenkins.gemspec +27 -0
- data/spec/fixtures/jobs_success.json +157 -0
- data/spec/fixtures/views_success.json +165 -0
- data/spec/lib/adapter_spec.rb +110 -0
- data/spec/spec_helper.rb +99 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f33c35f303ffaf542b32d28d074d8387357f90b
|
4
|
+
data.tar.gz: 40c019a90df163b16ad653befc3258c8f8682449
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bfcc93eea8500de3649b51a4c7a635c097ea693702a255ca9e414682d29bc6956d22c15b934d8d268ef2ee1767e0329c565aa2d5b339fd0883da16705c55e6f5
|
7
|
+
data.tar.gz: dc32af7e03167bd77b412a87aa84830ad39a41c3a235ddfeeb0d6317c8f728f452b9d987009767e1d85cf737950ebfe4c13fc84576fc1b639dca37dfa8cee407
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Adam Kerr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# SimpleJenkins
|
2
|
+
|
3
|
+
A super simple API for interacting with jenkins. Currently only does 3 things: fetching jobs, fetching views, building jobs
|
4
|
+
|
5
|
+
This gem was extracted from another project, as such it has not had a lot of TLC nor is it likely to in the near future.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'simple_jenkins'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install simple_jenkins
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
adapter = SimpleJenkins::Adapter.new
|
27
|
+
|
28
|
+
jobs = adapter.fetch_jobs
|
29
|
+
views = adapter.fetch_views
|
30
|
+
|
31
|
+
adapter.build_job(jobs.first)
|
32
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "base64"
|
2
|
+
|
3
|
+
module SimpleJenkins
|
4
|
+
class Adapter
|
5
|
+
def initialize(url, username: nil, password: nil)
|
6
|
+
@auth = "#{username}:#{password}" if username && password
|
7
|
+
@jenkins_url = url
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_job(job, params = {})
|
11
|
+
if params.empty?
|
12
|
+
path = URI::encode("#{@jenkins_url}/job/#{job.name}/build")
|
13
|
+
else
|
14
|
+
path = URI::encode("#{@jenkins_url}/job/#{job.name}/buildWithParameters")
|
15
|
+
end
|
16
|
+
|
17
|
+
result = RestClient.post(path, params, headers)
|
18
|
+
|
19
|
+
return Response.new(
|
20
|
+
code: result.code,
|
21
|
+
message: result
|
22
|
+
)
|
23
|
+
|
24
|
+
rescue RestClient::Exception => e
|
25
|
+
return Response.new(
|
26
|
+
code: e.response.code,
|
27
|
+
message: e.response
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fetch_jobs
|
32
|
+
attrs = extract_attrs(Job)
|
33
|
+
|
34
|
+
path = "#{@jenkins_url}/api/json?tree=jobs[#{attrs.join(",")}]"
|
35
|
+
|
36
|
+
api_response = RestClient.get(path, headers)
|
37
|
+
|
38
|
+
JSON
|
39
|
+
.parse(api_response.body)
|
40
|
+
.fetch("jobs", {})
|
41
|
+
.map { |job_hash| Job.new(job_hash) }
|
42
|
+
|
43
|
+
rescue RestClient::Exception => e
|
44
|
+
raise ApiException, e.response
|
45
|
+
end
|
46
|
+
|
47
|
+
def fetch_views
|
48
|
+
attrs = extract_attrs(View)
|
49
|
+
|
50
|
+
path = "#{@jenkins_url}/api/json?tree=views[#{attrs.join(",")}]"
|
51
|
+
api_response = RestClient.get(path, headers)
|
52
|
+
|
53
|
+
JSON
|
54
|
+
.parse(api_response.body)
|
55
|
+
.fetch("views", {})
|
56
|
+
.map { |view_hash| View.new(view_hash) }
|
57
|
+
|
58
|
+
rescue RestClient::Exception => e
|
59
|
+
raise ApiException, e.message
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def headers
|
65
|
+
return {} unless @auth
|
66
|
+
|
67
|
+
{
|
68
|
+
"Authorization" => "Basic #{Base64.encode64(@auth).chomp}"
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def extract_attrs(model)
|
73
|
+
model
|
74
|
+
.attribute_set
|
75
|
+
.map { |attr| get_attr_name(attr) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_attr_name(attr)
|
79
|
+
if attr.primitive.name.include?("SimpleJenkins::")
|
80
|
+
"#{attr.name}[#{extract_attrs(attr.primitive).join(",")}]"
|
81
|
+
elsif attr.is_a?(Virtus::Attribute::Collection) && attr.type.member_type != Axiom::Types::Object
|
82
|
+
"#{attr.name}[#{extract_attrs(attr.type.member_type).join(",")}]"
|
83
|
+
else
|
84
|
+
attr.name
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class ApiException < RuntimeError;
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module SimpleJenkins
|
5
|
+
class ParameterDefinition
|
6
|
+
include Virtus.value_object
|
7
|
+
|
8
|
+
values do
|
9
|
+
attribute :name, String
|
10
|
+
attribute :description, String
|
11
|
+
attribute :type, String
|
12
|
+
attribute :defaultParameterValue, Hash
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Build
|
17
|
+
include Virtus.value_object
|
18
|
+
|
19
|
+
values do
|
20
|
+
attribute :number, Integer
|
21
|
+
attribute :url, String
|
22
|
+
attribute :result, String
|
23
|
+
attribute :building, Boolean
|
24
|
+
end
|
25
|
+
|
26
|
+
def success?
|
27
|
+
result == 'SUCCESS'
|
28
|
+
end
|
29
|
+
|
30
|
+
def failure?
|
31
|
+
result == 'FAILURE'
|
32
|
+
end
|
33
|
+
|
34
|
+
def running?
|
35
|
+
building == true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Job
|
40
|
+
include Virtus.value_object
|
41
|
+
|
42
|
+
values do
|
43
|
+
attribute :name, String
|
44
|
+
attribute :url, String
|
45
|
+
attribute :color, String
|
46
|
+
|
47
|
+
# attribute :actions, { parameterDefinitions: [ParameterDefinition] }
|
48
|
+
attribute :buildable, Boolean
|
49
|
+
attribute :builds, [Build]
|
50
|
+
|
51
|
+
attribute :concurrentBuild, Boolean
|
52
|
+
attribute :description, String
|
53
|
+
attribute :displayName, String
|
54
|
+
attribute :displayNameOrNull, String
|
55
|
+
attribute :downstreamProjects, Array
|
56
|
+
attribute :firstBuild, Build
|
57
|
+
# attribute :healthReport, { description: String, iconClassName: String, iconUrl: String, score: Integer }
|
58
|
+
attribute :inQueue, Boolean
|
59
|
+
attribute :lastDependencies, Boolean
|
60
|
+
|
61
|
+
attribute :lastBuild, Build
|
62
|
+
attribute :lastCompletedBuild, Build
|
63
|
+
attribute :lastFailedBuild, Build
|
64
|
+
attribute :lastStableBuild, Build
|
65
|
+
attribute :lastSuccessfulBuild, Build
|
66
|
+
attribute :lastUnstableBuild, Build
|
67
|
+
attribute :lastUnsuccessfulBuild, Build
|
68
|
+
attribute :nextBuildNumber, Integer
|
69
|
+
|
70
|
+
attribute :property, Hash
|
71
|
+
|
72
|
+
attribute :queueItem, String
|
73
|
+
attribute :scm, Hash
|
74
|
+
attribute :upstreamProjects, Array
|
75
|
+
attribute :url, String
|
76
|
+
end
|
77
|
+
|
78
|
+
def url
|
79
|
+
URI::encode(@url)
|
80
|
+
end
|
81
|
+
|
82
|
+
def state
|
83
|
+
case color
|
84
|
+
when /disabled/
|
85
|
+
'DISA'
|
86
|
+
when /red/
|
87
|
+
'FAIL'
|
88
|
+
else
|
89
|
+
'SUCC'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def running?
|
94
|
+
lastBuild.running?
|
95
|
+
end
|
96
|
+
|
97
|
+
def success?
|
98
|
+
lastCompletedBuild.success?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_jenkins/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "SimpleJenkins"
|
8
|
+
spec.version = SimpleJenkins::VERSION
|
9
|
+
spec.authors = ["Adam Kerr"]
|
10
|
+
spec.email = ["adamk@nulogy.com"]
|
11
|
+
spec.summary = %q{A simple library for workign with jenkins}
|
12
|
+
spec.homepage = "http://github.com/nulogy/simple_jenkins"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "webmock", "~> 1.21"
|
24
|
+
|
25
|
+
spec.add_dependency "virtus", "~>1.0"
|
26
|
+
spec.add_dependency "rest-client", "~>1.8"
|
27
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
{
|
2
|
+
"jobs": [
|
3
|
+
{
|
4
|
+
"buildable": true,
|
5
|
+
"builds": [
|
6
|
+
{
|
7
|
+
"number": 12,
|
8
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/12/"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"number": 11,
|
12
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/11/"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"number": 10,
|
16
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/10/"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"number": 9,
|
20
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/9/"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"number": 8,
|
24
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/8/"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"number": 7,
|
28
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/7/"
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"number": 6,
|
32
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/6/"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"number": 5,
|
36
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/5/"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"number": 4,
|
40
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/4/"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"number": 3,
|
44
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/3/"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"number": 2,
|
48
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/2/"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"number": 1,
|
52
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/1/"
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"color": "blue",
|
56
|
+
"concurrentBuild": false,
|
57
|
+
"description": "",
|
58
|
+
"displayName": "680Nus",
|
59
|
+
"displayNameOrNull": null,
|
60
|
+
"downstreamProjects": [],
|
61
|
+
"firstBuild": {},
|
62
|
+
"inQueue": false,
|
63
|
+
"lastBuild": {},
|
64
|
+
"lastCompletedBuild": {},
|
65
|
+
"lastFailedBuild": {},
|
66
|
+
"lastStableBuild": {},
|
67
|
+
"lastSuccessfulBuild": {},
|
68
|
+
"lastUnstableBuild": null,
|
69
|
+
"lastUnsuccessfulBuild": {},
|
70
|
+
"name": "680Nus",
|
71
|
+
"nextBuildNumber": 13,
|
72
|
+
"property": [
|
73
|
+
{}
|
74
|
+
],
|
75
|
+
"queueItem": null,
|
76
|
+
"scm": {},
|
77
|
+
"upstreamProjects": [],
|
78
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/"
|
79
|
+
}, {
|
80
|
+
"buildable": true,
|
81
|
+
"builds": [
|
82
|
+
{
|
83
|
+
"number": 12,
|
84
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/12/"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"number": 11,
|
88
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/11/"
|
89
|
+
},
|
90
|
+
{
|
91
|
+
"number": 10,
|
92
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/10/"
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"number": 9,
|
96
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/9/"
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"number": 8,
|
100
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/8/"
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"number": 7,
|
104
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/7/"
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"number": 6,
|
108
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/6/"
|
109
|
+
},
|
110
|
+
{
|
111
|
+
"number": 5,
|
112
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/5/"
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"number": 4,
|
116
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/4/"
|
117
|
+
},
|
118
|
+
{
|
119
|
+
"number": 3,
|
120
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/3/"
|
121
|
+
},
|
122
|
+
{
|
123
|
+
"number": 2,
|
124
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/2/"
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"number": 1,
|
128
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/1/"
|
129
|
+
}
|
130
|
+
],
|
131
|
+
"color": "blue",
|
132
|
+
"concurrentBuild": false,
|
133
|
+
"description": "Runs Brakeman static analysis against CPI master branch when changes are detected.",
|
134
|
+
"displayName": "Brakeman (CPI)",
|
135
|
+
"displayNameOrNull": null,
|
136
|
+
"downstreamProjects": [],
|
137
|
+
"firstBuild": {},
|
138
|
+
"inQueue": false,
|
139
|
+
"lastBuild": {},
|
140
|
+
"lastCompletedBuild": {},
|
141
|
+
"lastFailedBuild": {},
|
142
|
+
"lastStableBuild": {},
|
143
|
+
"lastSuccessfulBuild": {},
|
144
|
+
"lastUnstableBuild": null,
|
145
|
+
"lastUnsuccessfulBuild": {},
|
146
|
+
"name": "Brakeman (CPI)",
|
147
|
+
"nextBuildNumber": 13,
|
148
|
+
"property": [
|
149
|
+
{}
|
150
|
+
],
|
151
|
+
"queueItem": null,
|
152
|
+
"scm": {},
|
153
|
+
"upstreamProjects": [],
|
154
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/"
|
155
|
+
}
|
156
|
+
]
|
157
|
+
}
|
@@ -0,0 +1,165 @@
|
|
1
|
+
{
|
2
|
+
"views": [
|
3
|
+
{
|
4
|
+
"description": null,
|
5
|
+
"jobs": [
|
6
|
+
{
|
7
|
+
"buildable": true,
|
8
|
+
"builds": [
|
9
|
+
{
|
10
|
+
"number": 12,
|
11
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/12/"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"number": 11,
|
15
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/11/"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"number": 10,
|
19
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/10/"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"number": 9,
|
23
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/9/"
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"number": 8,
|
27
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/8/"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"number": 7,
|
31
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/7/"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"number": 6,
|
35
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/6/"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"number": 5,
|
39
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/5/"
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"number": 4,
|
43
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/4/"
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"number": 3,
|
47
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/3/"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"number": 2,
|
51
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/2/"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"number": 1,
|
55
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/1/"
|
56
|
+
}
|
57
|
+
],
|
58
|
+
"color": "blue",
|
59
|
+
"concurrentBuild": false,
|
60
|
+
"description": "",
|
61
|
+
"displayName": "680Nus",
|
62
|
+
"displayNameOrNull": null,
|
63
|
+
"downstreamProjects": [],
|
64
|
+
"firstBuild": {},
|
65
|
+
"inQueue": false,
|
66
|
+
"lastBuild": {},
|
67
|
+
"lastCompletedBuild": {},
|
68
|
+
"lastFailedBuild": {},
|
69
|
+
"lastStableBuild": {},
|
70
|
+
"lastSuccessfulBuild": {},
|
71
|
+
"lastUnstableBuild": null,
|
72
|
+
"lastUnsuccessfulBuild": {},
|
73
|
+
"name": "680Nus",
|
74
|
+
"nextBuildNumber": 13,
|
75
|
+
"property": [
|
76
|
+
{}
|
77
|
+
],
|
78
|
+
"queueItem": null,
|
79
|
+
"scm": {},
|
80
|
+
"upstreamProjects": [],
|
81
|
+
"url": "http://squid.hq.nulogy.com/job/680Nus/"
|
82
|
+
}, {
|
83
|
+
"buildable": true,
|
84
|
+
"builds": [
|
85
|
+
{
|
86
|
+
"number": 12,
|
87
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/12/"
|
88
|
+
},
|
89
|
+
{
|
90
|
+
"number": 11,
|
91
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/11/"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"number": 10,
|
95
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/10/"
|
96
|
+
},
|
97
|
+
{
|
98
|
+
"number": 9,
|
99
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/9/"
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"number": 8,
|
103
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/8/"
|
104
|
+
},
|
105
|
+
{
|
106
|
+
"number": 7,
|
107
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/7/"
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"number": 6,
|
111
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/6/"
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"number": 5,
|
115
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/5/"
|
116
|
+
},
|
117
|
+
{
|
118
|
+
"number": 4,
|
119
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/4/"
|
120
|
+
},
|
121
|
+
{
|
122
|
+
"number": 3,
|
123
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/3/"
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"number": 2,
|
127
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/2/"
|
128
|
+
},
|
129
|
+
{
|
130
|
+
"number": 1,
|
131
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/1/"
|
132
|
+
}
|
133
|
+
],
|
134
|
+
"color": "blue",
|
135
|
+
"concurrentBuild": false,
|
136
|
+
"description": "Runs Brakeman static analysis against CPI master branch when changes are detected.",
|
137
|
+
"displayName": "Brakeman (CPI)",
|
138
|
+
"displayNameOrNull": null,
|
139
|
+
"downstreamProjects": [],
|
140
|
+
"firstBuild": {},
|
141
|
+
"inQueue": false,
|
142
|
+
"lastBuild": {},
|
143
|
+
"lastCompletedBuild": {},
|
144
|
+
"lastFailedBuild": {},
|
145
|
+
"lastStableBuild": {},
|
146
|
+
"lastSuccessfulBuild": {},
|
147
|
+
"lastUnstableBuild": null,
|
148
|
+
"lastUnsuccessfulBuild": {},
|
149
|
+
"name": "Brakeman (CPI)",
|
150
|
+
"nextBuildNumber": 13,
|
151
|
+
"property": [
|
152
|
+
{}
|
153
|
+
],
|
154
|
+
"queueItem": null,
|
155
|
+
"scm": {},
|
156
|
+
"upstreamProjects": [],
|
157
|
+
"url": "http://squid.hq.nulogy.com/job/Brakeman%20(CPI)/"
|
158
|
+
}
|
159
|
+
],
|
160
|
+
"name": "Test Servers",
|
161
|
+
"property": [],
|
162
|
+
"url": "http://squid.hq.nulogy.com/view/Test%20Servers/"
|
163
|
+
}
|
164
|
+
]
|
165
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
describe SimpleJenkins::Adapter do
|
5
|
+
|
6
|
+
let(:jenkins_url) { "test.com" }
|
7
|
+
let(:username) { "user" }
|
8
|
+
let(:password) { "pass" }
|
9
|
+
let(:adapter) { SimpleJenkins::Adapter.new(jenkins_url, username: username, password: password) }
|
10
|
+
|
11
|
+
describe "authentication" do
|
12
|
+
it "uses authentication" do
|
13
|
+
stub_request(:get, /user:pass@test\.com/).to_return(status: 200, body: "{}")
|
14
|
+
adapter.fetch_jobs
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#fetch_jobs" do
|
19
|
+
it "should query the correct url" do
|
20
|
+
stub_request(:get, "http://user:pass@test.com/api/json?tree=jobs%5Bname,url,color,buildable,builds%5Bnumber,url,result,building%5D,concurrentBuild,description,displayName,displayNameOrNull,downstreamProjects,firstBuild%5Bnumber,url,result,building%5D,inQueue,lastDependencies,lastBuild%5Bnumber,url,result,building%5D,lastCompletedBuild%5Bnumber,url,result,building%5D,lastFailedBuild%5Bnumber,url,result,building%5D,lastStableBuild%5Bnumber,url,result,building%5D,lastSuccessfulBuild%5Bnumber,url,result,building%5D,lastUnstableBuild%5Bnumber,url,result,building%5D,lastUnsuccessfulBuild%5Bnumber,url,result,building%5D,nextBuildNumber,property,queueItem,scm,upstreamProjects%5D")
|
21
|
+
.to_return(body: "{}")
|
22
|
+
|
23
|
+
adapter.fetch_jobs
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns a list of jobs" do
|
27
|
+
stub_successful_request(load_fixture("jobs_success.json"))
|
28
|
+
jobs = adapter.fetch_jobs
|
29
|
+
|
30
|
+
expect(jobs.count).to eq(2)
|
31
|
+
expect(jobs.map(&:name)).to match_array(["Brakeman (CPI)", "680Nus"])
|
32
|
+
end
|
33
|
+
|
34
|
+
it "fetches build information" do
|
35
|
+
stub_successful_request(load_fixture("jobs_success.json"))
|
36
|
+
jobs = adapter.fetch_jobs
|
37
|
+
|
38
|
+
job = jobs.detect { |job| job.name == "680Nus" }
|
39
|
+
build = job.builds.detect { |build| build.number == 10 }
|
40
|
+
|
41
|
+
expect(job.builds.count).to eq(12)
|
42
|
+
expect(build.number).to eq(10)
|
43
|
+
expect(build.url).to eq("http://squid.hq.nulogy.com/job/680Nus/10/")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#fetch_views" do
|
48
|
+
it "returns a list of views" do
|
49
|
+
stub_successful_request(load_fixture("views_success.json"))
|
50
|
+
views = adapter.fetch_views
|
51
|
+
|
52
|
+
expect(views.count).to eq(1)
|
53
|
+
expect(views.map(&:name)).to match_array(["Test Servers"])
|
54
|
+
expect(views.flat_map(&:jobs).map(&:name)).to match_array(["Brakeman (CPI)", "680Nus"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#build_job" do
|
59
|
+
let(:job_name) { "Job Name" }
|
60
|
+
let(:job) { SimpleJenkins::Job.new(name: job_name) }
|
61
|
+
|
62
|
+
it "builds without parameters" do
|
63
|
+
stub_jenkins_build(job_name, 201, "Message")
|
64
|
+
result = adapter.build_job(job)
|
65
|
+
|
66
|
+
expect(result).to have_attributes(
|
67
|
+
code: 201,
|
68
|
+
success?: true,
|
69
|
+
message: "Message"
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "builds with parameters" do
|
74
|
+
stub_jenkins_build(job_name, 201, "Messaging")
|
75
|
+
result = adapter.build_job(job, branch: "Something Else")
|
76
|
+
|
77
|
+
expect(result).to have_attributes(
|
78
|
+
code: 201,
|
79
|
+
success?: true,
|
80
|
+
message: "Messaging"
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "wraps the error case" do
|
85
|
+
stub_jenkins_build(job_name, 500, "Error Message")
|
86
|
+
result = adapter.build_job(job)
|
87
|
+
|
88
|
+
expect(result).to have_attributes(
|
89
|
+
code: 500,
|
90
|
+
success?: false,
|
91
|
+
message: "Error Message",
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def load_fixture(filename)
|
99
|
+
File.read("spec/fixtures/#{filename}")
|
100
|
+
end
|
101
|
+
|
102
|
+
def stub_successful_request(body)
|
103
|
+
stub_request(:get, /test\.com/).to_return(status: 200, body: body)
|
104
|
+
end
|
105
|
+
|
106
|
+
def stub_jenkins_build(job_name, status, message = nil)
|
107
|
+
stub_request(:post, URI.escape("user:pass@test.com/job/#{job_name}/build")).to_return(status: status, body: message)
|
108
|
+
stub_request(:post, URI.escape("user:pass@test.com/job/#{job_name}/buildWithParameters")).to_return(status: status, body: message)
|
109
|
+
end
|
110
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
=begin
|
46
|
+
# These two settings work together to allow you to limit a spec run
|
47
|
+
# to individual examples or groups you care about by tagging them with
|
48
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# get run.
|
50
|
+
config.filter_run :focus
|
51
|
+
config.run_all_when_everything_filtered = true
|
52
|
+
|
53
|
+
# Allows RSpec to persist some state between runs in order to support
|
54
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
55
|
+
# you configure your source control system to ignore this file.
|
56
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
57
|
+
|
58
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
59
|
+
# recommended. For more details, see:
|
60
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
61
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
63
|
+
config.disable_monkey_patching!
|
64
|
+
|
65
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
66
|
+
# be too noisy due to issues in dependencies.
|
67
|
+
config.warnings = true
|
68
|
+
|
69
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
70
|
+
# file, and it's useful to allow more verbose output when running an
|
71
|
+
# individual spec file.
|
72
|
+
if config.files_to_run.one?
|
73
|
+
# Use the documentation formatter for detailed output,
|
74
|
+
# unless a formatter has already been configured
|
75
|
+
# (e.g. via a command-line flag).
|
76
|
+
config.default_formatter = 'doc'
|
77
|
+
end
|
78
|
+
|
79
|
+
# Print the 10 slowest examples and example groups at the
|
80
|
+
# end of the spec run, to help surface which specs are running
|
81
|
+
# particularly slow.
|
82
|
+
config.profile_examples = 10
|
83
|
+
|
84
|
+
# Run specs in random order to surface order dependencies. If you find an
|
85
|
+
# order dependency and want to debug it, you can fix the order by providing
|
86
|
+
# the seed, which is printed after each run.
|
87
|
+
# --seed 1234
|
88
|
+
config.order = :random
|
89
|
+
|
90
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
91
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
92
|
+
# test failures related to randomization by passing the same `--seed` value
|
93
|
+
# as the one that triggered the failure.
|
94
|
+
Kernel.srand config.seed
|
95
|
+
=end
|
96
|
+
end
|
97
|
+
|
98
|
+
require "webmock/rspec"
|
99
|
+
require "simple_jenkins"
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SimpleJenkins
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Kerr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.21'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.21'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: virtus
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rest-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.8'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.8'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- adamk@nulogy.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".ruby-version"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/simple_jenkins.rb
|
112
|
+
- lib/simple_jenkins/adapter.rb
|
113
|
+
- lib/simple_jenkins/job.rb
|
114
|
+
- lib/simple_jenkins/response.rb
|
115
|
+
- lib/simple_jenkins/version.rb
|
116
|
+
- lib/simple_jenkins/view.rb
|
117
|
+
- simple_jenkins.gemspec
|
118
|
+
- spec/fixtures/jobs_success.json
|
119
|
+
- spec/fixtures/views_success.json
|
120
|
+
- spec/lib/adapter_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: http://github.com/nulogy/simple_jenkins
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.4.3
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: A simple library for workign with jenkins
|
146
|
+
test_files:
|
147
|
+
- spec/fixtures/jobs_success.json
|
148
|
+
- spec/fixtures/views_success.json
|
149
|
+
- spec/lib/adapter_spec.rb
|
150
|
+
- spec/spec_helper.rb
|