jenkins2 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89eb3788e74b3dca921bb2f0cbe47532563fda46
4
- data.tar.gz: e1f46c1ccabb5c259cc650dc9cdf1041ca627429
3
+ metadata.gz: 89372ed31079640dc0d1e310f3cb279c209846f3
4
+ data.tar.gz: 2ff0f1d37148a71cede4a61ffd9fb9dca76edaa5
5
5
  SHA512:
6
- metadata.gz: dd24ec55acd234fa995b76b35a826a67058fc59df0f4cec26319780bcfce28547f955f39ebc4b598a365c0a06429fca2598868eb8b2198fceea33ae01e5f5e55
7
- data.tar.gz: 9743457399f767bba6cea77a0e7d61bafd9207ca5da14fac17891f6230256984bc6c545f5236a48c80008f7000339e01a5cf2770ca2f950714c0ce58fe7cd0a1
6
+ metadata.gz: 28f396b6e2f8dbaf2f2e0f8ff6b222677d0e405b264af0f97c01d8ddd4ea34c3b53577ce555a31f5810b10b4ad47444c741a7a77db578caa773f69ed8f896461
7
+ data.tar.gz: c53ee77163b15abe3cdc5bc14b24d408d6c51faf8d8b768e8e4f5f499b97db7d420c020a6c4c1bd874eed030568b60ffa6c2292a932bffe41a20bc0ee216b810
@@ -1,31 +1,52 @@
1
1
  # Change Log
2
2
 
3
- ## [v0.1.0](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v0.1.0) (2017-10-11)
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-10-25)
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 has been
4
- tested with Jenkins 2.19.1 LTS.
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
- ## Credentials
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
- # Installation
10
+ - Jenkins version
11
+ - Quiet Down
12
+ - Cancel Quiet Down
13
+ - Safe Restart
14
+ - Immediate Restart
37
15
 
38
- gem install jenkins2
16
+ ### Users / People
39
17
 
40
- # Configuration
18
+ - Get authenticated user (who-am-i)
41
19
 
42
- The gem does not require any configuration. However, if your Jenkins is secured you will have to
43
- provide credentials with every CLI call.
20
+ ### Node / Slave / Computer
44
21
 
45
- jenkins2 -s http://jenkins.example.com -u admin -k mysecretkey offline-node -n mynode
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
- This can be avoided by creating a json configuration file like this
31
+ ### Plugins
48
32
 
49
- {
50
- "server": "http://jenkins.example.com",
51
- "user": "admin",
52
- "key": "mysecretkey"
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
- By default Jenkins2 expects this file to be at ~/.jenkins2.json, but you can provide your own path
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
- jenkins2 -c offline-node -n mynode # => -c switch tells Jenkins2 to read configuration file
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
- # Usage
86
+ Or use it in your ruby code:
61
87
 
62
- Either run it from command line:
88
+ ```ruby
89
+ require 'jenkins2'
63
90
 
64
- jenkins2 -s http://jenkins.example.com offline-node -n mynode
65
- jenkins2 --help # => for help and list of available commands
66
- jenkins2 --help <command> # => for help on particular command
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
- Or use it in your ruby code:
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
- require 'jenkins2'
71
- jc = Jenkins2::Client.new( server: 'http://jenkins.example.com' )
72
- jc.version
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
- # License
126
+ ## License
76
127
 
77
128
  MIT - see the accompanying [LICENSE](LICENSE) file for details.
78
129
 
79
- # Changelog
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
- # Contributing
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 follows GitHub Script
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
- ## Bootstrap
141
+ ### Bootstrap
91
142
 
92
143
  After cloning the project, run:
93
144
 
94
- script/bootstrap
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
- ## Tests
151
+ ### Tests
99
152
 
100
- The project is expected to be heavily tested :) with unit and integratin tests. To run unit tests,
101
- you will need to have some gems installed (see jenkins2.gemspec -> development\_dependencies or
102
- run bootstrap script). To run unit tests run
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
- script/unit_test
157
+ ```sh
158
+ $ script/test
159
+ ```
105
160
 
106
- Integration tests are run against a Jenkins server. Currently they require an lxd to setup it.
107
- To run integration tests type
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
- script/integration_test
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
- This will start Jenkins in lxd container, run the tests and then kill the container.
171
+ If you want to run just unit tests, you can do it through rake task:
112
172
 
113
- ## Continuous Integration
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
- If you would like to automate test runs the progect already has [Jenkinsfile](Jenkinsfile) for
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
- script/cibuild
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
- and then collects the data from the generated reports.
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.
@@ -1,4 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative '../lib/jenkins2'
4
- Jenkins2::CommandLine.new( ARGV ).run
5
+
6
+ result = Jenkins2::CLI.new.parse(ARGV).call
7
+ if result.is_a? String
8
+ puts result
9
+ elsif !result
10
+ exit 1
11
+ end
@@ -1,5 +1,10 @@
1
- require_relative 'jenkins2/command_line'
2
- require_relative 'jenkins2/version'
3
- require_relative 'jenkins2/log'
4
- require_relative 'jenkins2/try'
5
- require_relative 'jenkins2/wait'
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
@@ -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