jbcm 0.0.1
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 +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +89 -0
- data/Rakefile +2 -0
- data/jbcm.gemspec +26 -0
- data/lib/jbcm/version.rb +3 -0
- data/lib/jbcm.rb +82 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e5f32f9df9b37695be68986c1ea235d00a01642
|
4
|
+
data.tar.gz: c7d5b037461cf310f7eeb203e3d4d1f8b1f93108
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 173f92dc07f5323faf9e1509f5a1f607e565d40e5227c9f0829655db4601e442f356ed2bec4900f1f238b574a822180b5289d3f8591315c78c0bdd91d422879e
|
7
|
+
data.tar.gz: dc60aa6b10ca1b4a4b1e24465845769e82fb25ad4b955847b50b3120c51c1f22af9b842c9ca46768b6afcd0d3a58e4c20106c94cf93ee56bb084bc7acacbde12
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 CHINDA, Kazuyuki
|
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,89 @@
|
|
1
|
+
# Jbcm
|
2
|
+
|
3
|
+
Jenkins job's build command manager
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'jbcm'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install jbcm
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Initialize Jenkins Client
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'jbcm'
|
27
|
+
|
28
|
+
cli = Jbcm::Client.new(
|
29
|
+
user_name: 'user',
|
30
|
+
api_token: 'apitoken or password',
|
31
|
+
hostname: 'jenkins.example.com')
|
32
|
+
```
|
33
|
+
|
34
|
+
Jbcm::Client initialize params is below
|
35
|
+
|
36
|
+
```
|
37
|
+
user_name (required)
|
38
|
+
api_token or password (required)
|
39
|
+
hostname (required)
|
40
|
+
scheme (default: 'https')
|
41
|
+
port (default: '443')
|
42
|
+
```
|
43
|
+
|
44
|
+
### Fetch job's list
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
cli.jobs
|
48
|
+
```
|
49
|
+
|
50
|
+
or
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
cli.jobs(raw: true)
|
54
|
+
```
|
55
|
+
|
56
|
+
### Manage job's build command
|
57
|
+
|
58
|
+
fetch job's config
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
job = cli.job(job_name)
|
62
|
+
```
|
63
|
+
|
64
|
+
see config
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
job.config
|
68
|
+
```
|
69
|
+
|
70
|
+
see build command
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
job.build_command
|
74
|
+
```
|
75
|
+
|
76
|
+
update build command
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
job.build_command = NEW_COMMAND
|
80
|
+
job.update!
|
81
|
+
```
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
1. Fork it ( https://github.com/[my-github-username]/jbcm/fork )
|
86
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/jbcm.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jbcm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jbcm"
|
8
|
+
spec.version = Jbcm::VERSION
|
9
|
+
spec.authors = ["CHINDA, Kazuyuki"]
|
10
|
+
spec.email = ["ckazuyuki@gmail.com"]
|
11
|
+
spec.summary = "Jenkins job's build command manager"
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = "https://github.com/ckazu/jbcm"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday', '>= 0.9.1'
|
22
|
+
spec.add_dependency 'ox', '> 2.2'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
data/lib/jbcm/version.rb
ADDED
data/lib/jbcm.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'jbcm/version'
|
2
|
+
require 'faraday'
|
3
|
+
require 'json'
|
4
|
+
require 'ox'
|
5
|
+
|
6
|
+
module Jbcm
|
7
|
+
class Client
|
8
|
+
attr_reader :user_name, :api_token, :password, :scheme, :hostname, :port
|
9
|
+
|
10
|
+
def initialize(opts = {})
|
11
|
+
@user_name = opts[:user_name]
|
12
|
+
@api_token = opts[:api_token]
|
13
|
+
@api_token = opts[:password] if opts[:password]
|
14
|
+
@scheme = opts[:scheme] || 'https'
|
15
|
+
@hostname = opts[:hostname]
|
16
|
+
@port = opts[:port] || '443'
|
17
|
+
end
|
18
|
+
|
19
|
+
def conn
|
20
|
+
conn ||= Faraday::Connection.new(url: "#{scheme}://#{user_name}:#{api_token}@#{hostname}:#{port}") do |builder|
|
21
|
+
builder.use Faraday::Request::UrlEncoded
|
22
|
+
builder.use Faraday::Adapter::NetHttp
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def jobs(opts={})
|
27
|
+
Jbcm::Client::Job.new(self).list(opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
def job(job_name)
|
31
|
+
Jbcm::Client::Job.new(self, job_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
class Job
|
35
|
+
attr_reader :cli, :job_name
|
36
|
+
|
37
|
+
def initialize(cli, job_name = nil)
|
38
|
+
@cli = cli
|
39
|
+
@job_name = job_name
|
40
|
+
end
|
41
|
+
|
42
|
+
def list(raw: false)
|
43
|
+
response = cli.conn.get('api/json')
|
44
|
+
if raw
|
45
|
+
JSON.parse(response.body)
|
46
|
+
else
|
47
|
+
JSON.parse(response.body)['jobs']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def config
|
52
|
+
@config ||= Ox.parse(cli.conn.get("job/#{job_name}/config.xml").body)
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_command
|
56
|
+
config.project.builders.send('hudson.tasks.Shell').command.nodes
|
57
|
+
end
|
58
|
+
|
59
|
+
def build_commnad=(build_command)
|
60
|
+
config.project.builders.send('hudson.tasks.Shell').command.nodes.pop
|
61
|
+
config.project.builders.send('hudson.tasks.Shell').command.nodes.push(build_command)
|
62
|
+
end
|
63
|
+
|
64
|
+
def update
|
65
|
+
cli.conn.post do |req|
|
66
|
+
req.url "job/#{job_name}/config.xml"
|
67
|
+
req.headers['Content-Type'] = 'application/xml'
|
68
|
+
req.body = Ox.dump(config)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def update!
|
73
|
+
request_result = update
|
74
|
+
if request_result.status == 200
|
75
|
+
$stdout.puts 'update successfully.'
|
76
|
+
else
|
77
|
+
fail "Update failed! return #{request_result.status}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jbcm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CHINDA, Kazuyuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ox
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- ckazuyuki@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- jbcm.gemspec
|
82
|
+
- lib/jbcm.rb
|
83
|
+
- lib/jbcm/version.rb
|
84
|
+
homepage: https://github.com/ckazu/jbcm
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.5.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Jenkins job's build command manager
|
108
|
+
test_files: []
|