jenkins2 0.1.0 → 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 +4 -4
- data/CHANGELOG.md +43 -22
- data/README.md +140 -76
- data/bin/jenkins2 +8 -1
- data/lib/jenkins2.rb +10 -5
- data/lib/jenkins2/api.rb +33 -0
- data/lib/jenkins2/api/computer.rb +49 -0
- data/lib/jenkins2/api/credentials.rb +151 -0
- data/lib/jenkins2/api/job.rb +50 -0
- data/lib/jenkins2/api/plugins.rb +55 -0
- data/lib/jenkins2/api/root.rb +34 -0
- data/lib/jenkins2/api/rud.rb +21 -0
- data/lib/jenkins2/api/user.rb +35 -0
- data/lib/jenkins2/api/view.rb +40 -0
- data/lib/jenkins2/cli.rb +157 -0
- data/lib/jenkins2/cli/credentials.rb +232 -0
- data/lib/jenkins2/cli/job.rb +48 -0
- data/lib/jenkins2/cli/nodes.rb +233 -0
- data/lib/jenkins2/cli/plugins.rb +101 -0
- data/lib/jenkins2/cli/root.rb +65 -0
- data/lib/jenkins2/cli/user.rb +16 -0
- data/lib/jenkins2/cli/view.rb +155 -0
- data/lib/jenkins2/connection.rb +90 -0
- data/lib/jenkins2/errors.rb +37 -0
- data/lib/jenkins2/log.rb +8 -7
- data/lib/jenkins2/resource_proxy.rb +46 -0
- data/lib/jenkins2/util.rb +67 -0
- data/lib/jenkins2/version.rb +3 -1
- metadata +33 -49
- data/lib/jenkins2/client.rb +0 -127
- data/lib/jenkins2/client/credential_commands.rb +0 -134
- data/lib/jenkins2/client/node_commands.rb +0 -105
- data/lib/jenkins2/client/plugin_commands.rb +0 -53
- data/lib/jenkins2/cmdparse.rb +0 -51
- data/lib/jenkins2/command_line.rb +0 -221
- data/lib/jenkins2/try.rb +0 -36
- data/lib/jenkins2/uri.rb +0 -10
- data/lib/jenkins2/wait.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89372ed31079640dc0d1e310f3cb279c209846f3
|
4
|
+
data.tar.gz: 2ff0f1d37148a71cede4a61ffd9fb9dca76edaa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28f396b6e2f8dbaf2f2e0f8ff6b222677d0e405b264af0f97c01d8ddd4ea34c3b53577ce555a31f5810b10b4ad47444c741a7a77db578caa773f69ed8f896461
|
7
|
+
data.tar.gz: c53ee77163b15abe3cdc5bc14b24d408d6c51faf8d8b768e8e4f5f499b97db7d420c020a6c4c1bd874eed030568b60ffa6c2292a932bffe41a20bc0ee216b810
|
data/CHANGELOG.md
CHANGED
@@ -1,31 +1,52 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [v1.0.0](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v1.0.0) (February 19, 2018)
|
4
|
+
|
5
|
+
### Tested With
|
6
|
+
|
7
|
+
- Jenkins 2.89.4
|
8
|
+
- ssh-credentials 1.13
|
9
|
+
- plain-credentials 1.4
|
10
|
+
- command-launcher 1.2
|
11
|
+
|
12
|
+
### Enhancements
|
13
|
+
|
14
|
+
- Completely refactored API and CLI.
|
15
|
+
- Log will write to stderr by default (instead of stdout).
|
16
|
+
- Can create/show/update/delete Views.
|
17
|
+
- Can create/show/update/delete Jobs.
|
18
|
+
- Can show existing Users, People.
|
19
|
+
- Can install plugin from file/url.
|
20
|
+
- Code is now checked with rubocop.
|
21
|
+
- Switched configuration file format to yaml.
|
22
|
+
- Integration tests are now run on bitbucket pipelines.
|
23
|
+
|
24
|
+
## [v0.1.0](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v0.1.0) (October 11, 2017)
|
4
25
|
|
5
26
|
### Enhancements
|
6
27
|
|
7
|
-
- Support Crumbs
|
8
|
-
- Can forcefully restart Jenkins
|
28
|
+
- Support Crumbs.
|
29
|
+
- Can forcefully restart Jenkins.
|
9
30
|
|
10
|
-
## [v0.0.2](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v0.0.2) (2016
|
31
|
+
## [v0.0.2](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v0.0.2) (October 25, 2016)
|
11
32
|
|
12
33
|
### Enhancements
|
13
34
|
|
14
|
-
- Hopefully this gem is now usable
|
15
|
-
- Get Jenkins version
|
16
|
-
- Prepare for / cancel Jenkins shutdown
|
17
|
-
- Wait for all nodes to be idle
|
18
|
-
- Set node temporarily offline / online
|
19
|
-
- Connect / Disconnect node
|
20
|
-
- Wait for node to become idle, check if node is idle
|
21
|
-
- Get node definition as XML
|
22
|
-
- Update node definition from XML
|
23
|
-
- Run [parameterized] build
|
24
|
-
- List installed plugins
|
25
|
-
- Install / uninstall a plugin by short name (i.e. ssh-credentials)
|
26
|
-
- Create username with password credential ( Requires credentials plugin on Jenkins )
|
27
|
-
- Create ssh username with private key credential ( Requires ssh-credentials plugin on Jenkins )
|
28
|
-
- Create secret string credential ( Requires plain-credentials plugin on Jenkins )
|
29
|
-
- Create secret file credential ( Requires plain-credentials plugin on Jenkins )
|
30
|
-
- Get credential by id
|
31
|
-
- List credentials
|
35
|
+
- Hopefully this gem is now usable.
|
36
|
+
- Get Jenkins version.
|
37
|
+
- Prepare for / cancel Jenkins shutdown.
|
38
|
+
- Wait for all nodes to be idle.
|
39
|
+
- Set node temporarily offline / online.
|
40
|
+
- Connect / Disconnect node.
|
41
|
+
- Wait for node to become idle, check if node is idle.
|
42
|
+
- Get node definition as XML.
|
43
|
+
- Update node definition from XML.
|
44
|
+
- Run [parameterized] build.
|
45
|
+
- List installed plugins.
|
46
|
+
- Install / uninstall a plugin by short name (i.e. ssh-credentials).
|
47
|
+
- Create username with password credential ( Requires credentials plugin on Jenkins ).
|
48
|
+
- Create ssh username with private key credential ( Requires ssh-credentials plugin on Jenkins ).
|
49
|
+
- Create secret string credential ( Requires plain-credentials plugin on Jenkins ).
|
50
|
+
- Create secret file credential ( Requires plain-credentials plugin on Jenkins ).
|
51
|
+
- Get credential by id.
|
52
|
+
- List credentials.
|
data/README.md
CHANGED
@@ -1,121 +1,185 @@
|
|
1
1
|
# Jenkins2
|
2
2
|
|
3
|
-
Jenkins2 gem is a command line interface and API client for Jenkins 2 CI Server. This gem
|
4
|
-
tested with Jenkins
|
5
|
-
|
6
|
-
# Features available
|
7
|
-
## Global
|
8
|
-
- Get Jenkins version
|
9
|
-
- Prepare for shutdown
|
10
|
-
- Cancel shutdown
|
11
|
-
- Wait for all nodes to be idle
|
12
|
-
|
13
|
-
## Node
|
14
|
-
- Set node temporarily offline / online
|
15
|
-
- Connect / Disconnect node
|
16
|
-
- Wait for node to become idle
|
17
|
-
- Get node definition as XML
|
18
|
-
- Update node definition from XML
|
19
|
-
|
20
|
-
## Job
|
21
|
-
- Run [parameterized] build
|
22
|
-
|
23
|
-
## Plugin
|
24
|
-
- List installed plugins
|
25
|
-
- Install / uninstall a plugin by short name (i.e. ssh-credentials)
|
3
|
+
Jenkins2 gem is a command line interface and API client for Jenkins 2 CI Server. This gem is
|
4
|
+
tested with latest Jenkins LTS. (See the [CHANGELOG](CHANGELOG.md) for exact versions.)
|
26
5
|
|
6
|
+
## Features available
|
27
7
|
|
28
|
-
|
29
|
-
- Create username with password credential ( Requires credentials plugin on Jenkins )
|
30
|
-
- Create ssh username with private key credential ( Requires ssh-credentials plugin on Jenkins )
|
31
|
-
- Create secret string credential ( Requires plain-credentials plugin on Jenkins )
|
32
|
-
- Create secret file credential ( Requires plain-credentials plugin on Jenkins )
|
33
|
-
- Get credential by id
|
34
|
-
- List credentials
|
8
|
+
### Global
|
35
9
|
|
36
|
-
|
10
|
+
- Jenkins version
|
11
|
+
- Quiet Down
|
12
|
+
- Cancel Quiet Down
|
13
|
+
- Safe Restart
|
14
|
+
- Immediate Restart
|
37
15
|
|
38
|
-
|
16
|
+
### Users / People
|
39
17
|
|
40
|
-
|
18
|
+
- Get authenticated user (who-am-i)
|
41
19
|
|
42
|
-
|
43
|
-
provide credentials with every CLI call.
|
20
|
+
### Node / Slave / Computer
|
44
21
|
|
45
|
-
|
22
|
+
- Create slave from config.xml
|
23
|
+
- Delete slave
|
24
|
+
- Toggle slave offline / online
|
25
|
+
- Launch slave agent
|
26
|
+
- Disconnect slave
|
27
|
+
- Get slave's config.xml
|
28
|
+
- List \[online\] slaves
|
29
|
+
- Get slave(s) states
|
46
30
|
|
47
|
-
|
31
|
+
### Plugins
|
48
32
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
33
|
+
- List installed plugins
|
34
|
+
- Install a plugin and its dependencies from update center (providing a short name e.g.
|
35
|
+
thinBackup).
|
36
|
+
- Install a plugin either from a file or an URL. Dependencies are not installed!
|
37
|
+
- Show plugin information
|
38
|
+
- Uninstall a plugin
|
39
|
+
|
40
|
+
### Credentials
|
41
|
+
|
42
|
+
- Create username with password credentials (Requires credentials plugin on Jenkins)
|
43
|
+
- Create ssh username with private key credentials (Requires ssh-credentials plugin on Jenkins)
|
44
|
+
- Create secret string credentials (Requires plain-credentials plugin on Jenkins)
|
45
|
+
- Create secret file credentials (Requires plain-credentials plugin on Jenkins)
|
46
|
+
- Get credentials by id
|
47
|
+
- Delete credentials
|
48
|
+
- List credentials in particular store and domain
|
49
|
+
|
50
|
+
### Views
|
51
|
+
|
52
|
+
- List views
|
53
|
+
- Get view configuraiton xml
|
54
|
+
- Update view configuraiton xml
|
55
|
+
- Create View
|
56
|
+
- Delete View
|
57
|
+
- Add job to view
|
58
|
+
- Remove job from view
|
59
|
+
|
60
|
+
### Jobs
|
61
|
+
|
62
|
+
- List jobs
|
63
|
+
- Create job from config.xml or by copying another one
|
64
|
+
- Set (Update) job's config.xml
|
65
|
+
- Get job's config.xml
|
66
|
+
- Delete job
|
67
|
+
- Enable, disable job
|
68
|
+
- Run build (with parameters, if required)
|
69
|
+
|
70
|
+
## Installation
|
71
|
+
|
72
|
+
```sh
|
73
|
+
$ gem install jenkins2
|
74
|
+
```
|
75
|
+
|
76
|
+
## Usage
|
54
77
|
|
55
|
-
|
56
|
-
with --config-file switch. This way the above mentioned command will be much shorter.
|
78
|
+
Either run it from command line:
|
57
79
|
|
58
|
-
|
80
|
+
```sh
|
81
|
+
$ jenkins2 -s http://jenkins.example.com offline-node -n mynode
|
82
|
+
$ jenkins2 --help # => for help and list of available commands
|
83
|
+
$ jenkins2 --help <command> # => for help on particular command
|
84
|
+
```
|
59
85
|
|
60
|
-
|
86
|
+
Or use it in your ruby code:
|
61
87
|
|
62
|
-
|
88
|
+
```ruby
|
89
|
+
require 'jenkins2'
|
63
90
|
|
64
|
-
|
65
|
-
|
66
|
-
|
91
|
+
jc = Jenkins2.connect(server: 'http://jenkins.example.com', user: 'admin', key: 'mysecretkey')
|
92
|
+
jc.version
|
93
|
+
jc.computer('mynode').toggle_offline( 'Some reason, why' )
|
94
|
+
```
|
67
95
|
|
68
|
-
|
96
|
+
## Configuration
|
97
|
+
|
98
|
+
The gem does not require any configuration. However, if your Jenkins is secured you will have to
|
99
|
+
provide credentials with every CLI call.
|
100
|
+
|
101
|
+
```sh
|
102
|
+
$ jenkins2 -s http://jenkins.example.com -u admin -k mysecretkey offline-node -n mynode
|
103
|
+
```
|
104
|
+
|
105
|
+
This can be avoided by creating a yaml configuration file like this
|
106
|
+
|
107
|
+
```yaml
|
108
|
+
---
|
109
|
+
:server: http://jenkins.example.com
|
110
|
+
:user: admin
|
111
|
+
:key: mysecretkey
|
112
|
+
:verbose: 3
|
113
|
+
:log: /var/log/jenkins2.log
|
114
|
+
```
|
115
|
+
|
116
|
+
and putting global options there. Jenkins will not read the file unless you use `-c` or
|
117
|
+
`--config-file` switches. If you use the switch, but omit the file path, the gem will look for
|
118
|
+
`.jenkins2.conf` in current directory.
|
119
|
+
|
120
|
+
This way the above mentioned command is much shorter
|
69
121
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
jc.offline_node( node: 'mynode' )
|
122
|
+
```sh
|
123
|
+
$ jenkins2 -c offline-node -n mynode # => -c switch tells Jenkins2 to read .jenkins2.conf file
|
124
|
+
```
|
74
125
|
|
75
|
-
|
126
|
+
## License
|
76
127
|
|
77
128
|
MIT - see the accompanying [LICENSE](LICENSE) file for details.
|
78
129
|
|
79
|
-
|
130
|
+
## Changelog
|
80
131
|
|
81
132
|
To see what has changed in recent versions see the [CHANGELOG](CHANGELOG.md).
|
82
133
|
Jenkins2 gem follows the [Semantic Versioning Policy](http://guides.rubygems.org/patterns).
|
83
134
|
|
84
|
-
|
135
|
+
## Contributing
|
85
136
|
|
86
137
|
Additional commands and bugfixes are welcome! Please fork and submit a pull request on an
|
87
|
-
individual branch per change. The project
|
138
|
+
individual branch per change. The project has a script folder which is inspired by GitHub Script
|
88
139
|
["Scripts To Rule Them All"] (https://github.com/github/scripts-to-rule-them-all) pattern.
|
89
140
|
|
90
|
-
|
141
|
+
### Bootstrap
|
91
142
|
|
92
143
|
After cloning the project, run:
|
93
144
|
|
94
|
-
|
145
|
+
```sh
|
146
|
+
$ script/bootstrap
|
147
|
+
```
|
95
148
|
|
96
149
|
to download gem and other dependencies (currently tested only on ubuntu xenial).
|
97
150
|
|
98
|
-
|
151
|
+
### Tests
|
99
152
|
|
100
|
-
The project is expected to be heavily tested :) with unit and integratin tests.
|
101
|
-
|
102
|
-
|
153
|
+
The project is expected to be heavily tested :) with unit and integratin tests.
|
154
|
+
Integration tests are run against a Jenkins server. Currently Jenkins server is set up in docker
|
155
|
+
container. To run all the tests (unit and integration ) type:
|
103
156
|
|
104
|
-
|
157
|
+
```sh
|
158
|
+
$ script/test
|
159
|
+
```
|
105
160
|
|
106
|
-
|
107
|
-
|
161
|
+
This will start Jenkins in docker container, run the tests and then kill the container. If you
|
162
|
+
want to just start the Jenkins in docker and then may be run tests several times against it, you
|
163
|
+
can do the following:
|
108
164
|
|
109
|
-
|
165
|
+
```sh
|
166
|
+
$ source script/jenkins_start # start jenkins
|
167
|
+
$ rake test:all # run all tests
|
168
|
+
```
|
169
|
+
Then, when you have finished running tests, run `script/jenkins_kill` to stop Jenkins in docker.
|
110
170
|
|
111
|
-
|
171
|
+
If you want to run just unit tests, you can do it through rake task:
|
112
172
|
|
113
|
-
|
173
|
+
```sh
|
174
|
+
$ rake test:unit
|
175
|
+
```
|
176
|
+
provided you have already installed all the dependences (see [jenkins2.gemspec](jenkins2.gemspec)
|
177
|
+
-> development\_dependencies or run [bootstrap script](script/bootstrap)).
|
114
178
|
|
115
|
-
|
116
|
-
quick and easy integration with Jenkins Pipelines. If you are using another CI server, just make
|
117
|
-
sure it runs
|
179
|
+
### Continuous Integration
|
118
180
|
|
119
|
-
|
181
|
+
The project uses Bitbucket Pipelines as CI environment. You can check out
|
182
|
+
[bitbucket-pipelines.yml](bitbucket-pipelines.yml) for the exact script.
|
120
183
|
|
121
|
-
|
184
|
+
Also there is a [Jenkinsfile](Jenkinsfile) for quick and easy integration with Jenkins Pipelines.
|
185
|
+
Unfortunately it is outdated now, but it can be still used as an example to start from.
|
data/bin/jenkins2
CHANGED
data/lib/jenkins2.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require_relative 'jenkins2/
|
4
|
-
require_relative 'jenkins2/
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'jenkins2/api'
|
4
|
+
require_relative 'jenkins2/cli'
|
5
|
+
|
6
|
+
module Jenkins2
|
7
|
+
def self.connect(**opts)
|
8
|
+
Jenkins2::API.new opts
|
9
|
+
end
|
10
|
+
end
|
data/lib/jenkins2/api.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'resource_proxy'
|
4
|
+
require_relative 'connection'
|
5
|
+
require_relative 'errors'
|
6
|
+
require_relative 'util'
|
7
|
+
require_relative 'api/credentials'
|
8
|
+
require_relative 'api/computer'
|
9
|
+
require_relative 'api/job'
|
10
|
+
require_relative 'api/plugins'
|
11
|
+
require_relative 'api/root'
|
12
|
+
require_relative 'api/user'
|
13
|
+
require_relative 'api/view'
|
14
|
+
|
15
|
+
module Jenkins2
|
16
|
+
class API
|
17
|
+
include Credentials
|
18
|
+
include Computer
|
19
|
+
include Job
|
20
|
+
include Plugins
|
21
|
+
include Root
|
22
|
+
include User
|
23
|
+
include View
|
24
|
+
|
25
|
+
attr_reader :connection
|
26
|
+
|
27
|
+
def initialize(**options)
|
28
|
+
@connection = Jenkins2::Connection.new(options[:server]).
|
29
|
+
basic_auth options[:user], options[:key]
|
30
|
+
Log.init(log: options[:log], verbose: options[:verbose])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'rud'
|
4
|
+
|
5
|
+
require 'cgi'
|
6
|
+
|
7
|
+
module Jenkins2
|
8
|
+
class API
|
9
|
+
module Computer
|
10
|
+
def computer(id=nil, **params)
|
11
|
+
proxy = Proxy.new connection, 'computer', params
|
12
|
+
proxy.id = id
|
13
|
+
proxy
|
14
|
+
end
|
15
|
+
|
16
|
+
class Proxy < ::Jenkins2::ResourceProxy
|
17
|
+
attr_accessor :id
|
18
|
+
include ::Jenkins2::API::RUD
|
19
|
+
|
20
|
+
def launch_agent
|
21
|
+
connection.post(build_path('launchSlaveAgent')).code == '302'
|
22
|
+
end
|
23
|
+
|
24
|
+
def create
|
25
|
+
form_data = { name: @id, type: 'hudson.slaves.DumbSlave$DescriptorImpl', json: '{}' }
|
26
|
+
@id = nil
|
27
|
+
path = build_path 'doCreateItem'
|
28
|
+
connection.post(path, ::URI.encode_www_form(form_data)).code == '302'
|
29
|
+
end
|
30
|
+
|
31
|
+
def disconnect(offline_message=nil)
|
32
|
+
path = build_path 'doDisconnect'
|
33
|
+
body = "offlineMessage=#{::CGI.escape offline_message}" unless offline_message.nil?
|
34
|
+
connection.post(path, body).code == '302'
|
35
|
+
end
|
36
|
+
|
37
|
+
def toggle_offline(offline_message=nil)
|
38
|
+
path = build_path 'toggleOffline'
|
39
|
+
body = "offlineMessage=#{::CGI.escape offline_message}" unless offline_message.nil?
|
40
|
+
connection.post(path, body).code == '302'
|
41
|
+
end
|
42
|
+
|
43
|
+
def online?
|
44
|
+
not ( offline or temporarilyOffline)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|