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.
@@ -0,0 +1,232 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jenkins2
4
+ class CLI
5
+ class CreateCredentialsByXml < CLI
6
+ def self.description
7
+ 'Create credential by reading stdin as an XML configuration.'
8
+ end
9
+
10
+ def add_options
11
+ parser.separator 'Mandatory arguments:'
12
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
13
+ options[:store] = s
14
+ end
15
+ parser.on '--domain DOMAIN', 'Domain id. (e.g. "_")' do |d|
16
+ options[:domain] = d
17
+ end
18
+ end
19
+
20
+ def mandatory_arguments
21
+ super + %i[store domain]
22
+ end
23
+
24
+ def run
25
+ jc.credentials.store(options[:store]).domain(options[:domain]).create($stdin.read)
26
+ end
27
+ end
28
+
29
+ class CreateCredentialsDomainByXml < CLI
30
+ def self.description
31
+ 'Create credential domain by reading stdin as an XML configuration.'
32
+ end
33
+
34
+ def add_options
35
+ parser.separator 'Mandatory arguments:'
36
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
37
+ options[:store] = s
38
+ end
39
+ end
40
+
41
+ def mandatory_arguments
42
+ super + %i[store]
43
+ end
44
+
45
+ def run
46
+ jc.credentials.store(options[:store]).create_domain($stdin.read)
47
+ end
48
+ end
49
+
50
+ class DeleteCredentials < CLI
51
+ def self.description
52
+ 'Delete credentials.'
53
+ end
54
+
55
+ def add_options
56
+ parser.separator 'Mandatory arguments:'
57
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
58
+ options[:store] = s
59
+ end
60
+ parser.on '--domain DOMAIN', 'Domain id. (e.g. "_")' do |d|
61
+ options[:domain] = d
62
+ end
63
+ parser.on '--credential ID', 'Credential id.' do |c|
64
+ options[:credential] = c
65
+ end
66
+ end
67
+
68
+ def mandatory_arguments
69
+ super + %i[store domain credential]
70
+ end
71
+
72
+ def run
73
+ jc.credentials.store(options[:store]).domain(options[:domain]).
74
+ credential(options[:credential]).delete
75
+ end
76
+ end
77
+
78
+ class DeleteCredentialsDomain < CLI
79
+ def self.description
80
+ 'Delete credentials domain.'
81
+ end
82
+
83
+ def add_options
84
+ parser.separator 'Mandatory arguments:'
85
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
86
+ options[:store] = s
87
+ end
88
+ parser.on '--domain DOMAIN', 'Domain id. (e.g. "_")' do |d|
89
+ options[:domain] = d
90
+ end
91
+ end
92
+
93
+ def mandatory_arguments
94
+ super + %i[store domain]
95
+ end
96
+
97
+ def run
98
+ jc.credentials.store(options[:store]).domain(options[:domain]).delete
99
+ end
100
+ end
101
+
102
+ class GetCredentialsAsXml < CLI
103
+ def self.description
104
+ 'Get a credential as XML (secrets redacted).'
105
+ end
106
+
107
+ def add_options
108
+ parser.separator 'Mandatory arguments:'
109
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
110
+ options[:store] = s
111
+ end
112
+ parser.on '--domain DOMAIN', 'Domain id. (e.g. "_")' do |d|
113
+ options[:domain] = d
114
+ end
115
+ parser.on '--credential ID', 'Credential id.' do |c|
116
+ options[:credential] = c
117
+ end
118
+ end
119
+
120
+ def mandatory_arguments
121
+ super + %i[store domain credential]
122
+ end
123
+
124
+ def run
125
+ jc.credentials.store(options[:store]).domain(options[:domain]).
126
+ credential(options[:credential]).config_xml
127
+ end
128
+ end
129
+
130
+ class GetCredentialsDomainAsXml < CLI
131
+ def self.description
132
+ 'Get credentials domain as XML.'
133
+ end
134
+
135
+ def add_options
136
+ parser.separator 'Mandatory arguments:'
137
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
138
+ options[:store] = s
139
+ end
140
+ parser.on '--domain DOMAIN', 'Domain id. (e.g. "_")' do |d|
141
+ options[:domain] = d
142
+ end
143
+ end
144
+
145
+ def mandatory_arguments
146
+ super + %i[store domain]
147
+ end
148
+
149
+ def run
150
+ jc.credentials.store(options[:store]).domain(options[:domain]).config_xml
151
+ end
152
+ end
153
+
154
+ class ListCredentials < CLI
155
+ def self.description
156
+ 'Lists credentials in a specific store.'
157
+ end
158
+
159
+ def add_options
160
+ parser.separator 'Mandatory arguments:'
161
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
162
+ options[:store] = s
163
+ end
164
+ end
165
+
166
+ def mandatory_arguments
167
+ super + [:store]
168
+ end
169
+
170
+ def run
171
+ jc.credentials.store(options[:store], depth: 2).domains.to_h.collect do |_, v|
172
+ "Domain: #{v.displayName}\n" +
173
+ v.credentials.collect do |crd|
174
+ "#{crd.id} - #{crd.displayName}"
175
+ end.join("\n")
176
+ end.join("\n")
177
+ end
178
+ end
179
+
180
+ class UpdateCredentialsByXml < CLI
181
+ def self.description
182
+ 'Update credentials by XML.'
183
+ end
184
+
185
+ def add_options
186
+ parser.separator 'Mandatory arguments:'
187
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
188
+ options[:store] = s
189
+ end
190
+ parser.on '--domain DOMAIN', 'Domain id. (e.g. "_")' do |d|
191
+ options[:domain] = d
192
+ end
193
+ parser.on '--credential ID', 'Credential id.' do |c|
194
+ options[:credential] = c
195
+ end
196
+ end
197
+
198
+ def mandatory_arguments
199
+ super + %i[store domain credential]
200
+ end
201
+
202
+ def run
203
+ jc.credentials.store(options[:store]).domain(options[:domain]).
204
+ credential(options[:credential]).update($stdin.read)
205
+ end
206
+ end
207
+
208
+ class UpdateCredentialsDomainByXml < CLI
209
+ def self.description
210
+ 'Update credentials domain by XML.'
211
+ end
212
+
213
+ def add_options
214
+ parser.separator 'Mandatory arguments:'
215
+ parser.on '--store STORE', 'Store id. (e.g. "system")' do |s|
216
+ options[:store] = s
217
+ end
218
+ parser.on '--domain DOMAIN', 'Domain id. (e.g. "_")' do |d|
219
+ options[:domain] = d
220
+ end
221
+ end
222
+
223
+ def mandatory_arguments
224
+ super + %i[store domain]
225
+ end
226
+
227
+ def run
228
+ jc.credentials.store(options[:store]).domain(options[:domain]).update($stdin.read)
229
+ end
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jenkins2
4
+ class CLI
5
+ class ListJobs < CLI
6
+ def self.description
7
+ 'Lists all jobs in a specific view or item group.'
8
+ end
9
+
10
+ private
11
+
12
+ def add_options
13
+ parser.separator 'Optional arguments:'
14
+ parser.on '-n', '--name NAME', 'Name of the view. Default - all' do |n|
15
+ options[:name] = n
16
+ end
17
+ end
18
+
19
+ def run; end
20
+ end
21
+
22
+ class CopyJob < CLI
23
+ def self.description
24
+ 'Copies a job.'
25
+ end
26
+
27
+ private
28
+
29
+ def add_options
30
+ parser.separator 'Mandatory arguments:'
31
+ parser.on '-f', '--from NAME', 'Name of the job to copy.' do |f|
32
+ options[:from] = f
33
+ end
34
+ parser.on '-n', '--name NAME', 'Name of the new job, to be created.' do |n|
35
+ options[:name] = n
36
+ end
37
+ end
38
+
39
+ def mandatory_arguments
40
+ super + %i[name from]
41
+ end
42
+
43
+ def run
44
+ jc.job(options[:name]).copy(options[:from])
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,233 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jenkins2
4
+ class CLI
5
+ class ConnectNode < CLI
6
+ def self.description
7
+ 'Reconnect node(s).'
8
+ end
9
+
10
+ def add_options
11
+ parser.separator 'Mandatory arguments:'
12
+ parser.on '-n', '--name X,Y,..', Array, 'Slave name, or "(master)" for master, '\
13
+ 'comma-separated list is supported.' do |n|
14
+ options[:name] = n
15
+ end
16
+ end
17
+
18
+ def run
19
+ options[:name].all? do |name|
20
+ jc.computer(name).launch_agent
21
+ end
22
+ end
23
+ end
24
+
25
+ class CreateNode < CLI
26
+ def self.description
27
+ 'Creates a new node by reading stdin for an XML configuration.'
28
+ end
29
+
30
+ def add_options
31
+ parser.separator 'Mandatory arguments:'
32
+ parser.on '-n', '--name NAME', 'Name of the node.' do |n|
33
+ options[:name] = n
34
+ end
35
+ end
36
+
37
+ def run
38
+ jc.computer(options[:name]).create and
39
+ jc.computer(options[:name]).update($stdin.read)
40
+ end
41
+ end
42
+
43
+ class DeleteNode < CLI
44
+ def self.description
45
+ 'Deletes node(s).'
46
+ end
47
+
48
+ def add_options
49
+ parser.separator 'Mandatory arguments:'
50
+ parser.on '-n', '--name X,Y,..', Array, 'Names of nodes to delete.' do |n|
51
+ options[:name] = n
52
+ end
53
+ end
54
+
55
+ def run
56
+ options[:name].all? do |name|
57
+ jc.computer(name).delete
58
+ end
59
+ end
60
+ end
61
+
62
+ class DisconnectNode < CLI
63
+ def self.description
64
+ 'Disconnects node(s).'
65
+ end
66
+
67
+ def add_options
68
+ parser.separator 'Mandatory arguments:'
69
+ parser.on '-n', '--name X,Y,..', Array, 'Slave name, or "(master)" for master, '\
70
+ 'comma-separated list is supported.' do |n|
71
+ options[:name] = n
72
+ end
73
+ parser.separator 'Optional arguments:'
74
+ parser.on '-m', '--message TEXT', 'Record the reason about why you are disconnecting the'\
75
+ ' node(s).' do |m|
76
+ options[:message] = m
77
+ end
78
+ end
79
+
80
+ def run
81
+ options[:name].all? do |name|
82
+ jc.computer(name).disconnect(options[:message])
83
+ end
84
+ end
85
+ end
86
+
87
+ class GetNode < CLI
88
+ def self.description
89
+ 'Dumps the node definition XML to stdout.'
90
+ end
91
+
92
+ def add_options
93
+ parser.separator 'Mandatory arguments:'
94
+ parser.on '-n', '--name NAME', 'Name of the node.' do |n|
95
+ options[:name] = n
96
+ end
97
+ end
98
+
99
+ def run
100
+ jc.computer(options[:name]).config_xml
101
+ end
102
+ end
103
+
104
+ class ListNode < CLI
105
+ def self.description
106
+ 'Outputs the node list.'
107
+ end
108
+
109
+ def run
110
+ jc.computer.computer.collect(&:displayName).join("\n")
111
+ end
112
+ end
113
+
114
+ class ListOnlineNode < CLI
115
+ def self.description
116
+ 'Outputs the online node list.'
117
+ end
118
+
119
+ def run
120
+ jc.computer.computer.delete_if{|i| i.offline or i.temporarilyOffline }.
121
+ collect(&:displayName).join("\n")
122
+ end
123
+ end
124
+
125
+ class OfflineNode < CLI
126
+ def self.description
127
+ 'Stop using a node for performing builds temporarily, until the next "online-node" '\
128
+ 'command.'
129
+ end
130
+
131
+ def add_options
132
+ parser.separator 'Mandatory arguments:'
133
+ parser.on '-n', '--name NAME', 'Name of the node or "(master)" for master.' do |n|
134
+ options[:name] = n
135
+ end
136
+ parser.separator 'Optional arguments:'
137
+ parser.on '-m', '--message TEXT', 'Record the reason about why you are disconnecting the'\
138
+ ' node.' do |m|
139
+ options[:message] = m
140
+ end
141
+ end
142
+
143
+ def run
144
+ return if jc.computer(options[:name]).temporarilyOffline
145
+ jc.computer(options[:name]).toggle_offline(options[:message])
146
+ end
147
+ end
148
+
149
+ class OnlineNode < CLI
150
+ def self.description
151
+ 'Resume using a node for performing builds, to cancel out the earlier "offline-node" '\
152
+ 'command.'
153
+ end
154
+
155
+ def add_options
156
+ parser.separator 'Mandatory arguments:'
157
+ parser.on '-n', '--name NAME', 'Name of the node or "(master)" for master.' do |n|
158
+ options[:name] = n
159
+ end
160
+ end
161
+
162
+ def run
163
+ return unless jc.computer(options[:name]).temporarilyOffline
164
+ jc.computer(options[:name]).toggle_offline
165
+ end
166
+ end
167
+
168
+ class UpdateNode < CLI
169
+ def self.description
170
+ 'Updates the node definition XML from stdin. The opposite of the get-node command.'
171
+ end
172
+
173
+ def add_options
174
+ parser.separator 'Mandatory arguments:'
175
+ parser.on '-n', '--name NAME', 'Name of the node.' do |n|
176
+ options[:name] = n
177
+ end
178
+ end
179
+
180
+ def run
181
+ jc.computer(options[:name]).update($stdin.read)
182
+ end
183
+ end
184
+
185
+ class WaitNodeOffline < CLI
186
+ def self.description
187
+ 'Wait for a node to become offline.'
188
+ end
189
+
190
+ def add_options
191
+ parser.separator 'Mandatory arguments:'
192
+ parser.on '-n', '--name NAME', 'Name of the node.' do |n|
193
+ options[:name] = n
194
+ end
195
+ parser.separator 'Optional arguments:'
196
+ parser.on '-w', '--wait MINUTES', Integer, 'Maximum number of minutes to wait. Default is '\
197
+ '60.' do |w|
198
+ options[:wait] = w
199
+ end
200
+ end
201
+
202
+ def run
203
+ Jenkins2::Util.wait(max_wait_minutes: options[:wait]) do
204
+ !jc.computer(options[:name]).online?
205
+ end
206
+ end
207
+ end
208
+
209
+ class WaitNodeOnline < CLI
210
+ def self.description
211
+ 'Wait for a node to become online.'
212
+ end
213
+
214
+ def add_options
215
+ parser.separator 'Mandatory arguments:'
216
+ parser.on '-n', '--name NAME', 'Name of the node.' do |n|
217
+ options[:name] = n
218
+ end
219
+ parser.separator 'Optional arguments:'
220
+ parser.on '-w', '--wait MINUTES', Integer, 'Maximum number of minutes to wait. Default is '\
221
+ '60.' do |w|
222
+ options[:wait] = w
223
+ end
224
+ end
225
+
226
+ def run
227
+ Jenkins2::Util.wait(max_wait_minutes: options[:wait]) do
228
+ jc.computer(options[:name]).online?
229
+ end
230
+ end
231
+ end
232
+ end
233
+ end