blob: 5b6f7eabcb4ee2fa70bb940a4b9cd47164b84fc1 [file] [log] [blame]
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +02001=======
2Jenkins
3=======
4
Ales Komarek4c0bab12016-01-22 12:10:50 +01005Jenkins is an application that monitors executions of repeated jobs, such as building a software project or jobs run by cron.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +02006
7Available states
8================
9
10.. contents::
11 :local:
12
13``jenkins.master``
14------------------
15
Ales Komareke5a1ed62016-08-27 12:02:48 +020016Setup jenkins master.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020017
18``jenkins.slave``
19-----------------
20
Ales Komareke5a1ed62016-08-27 12:02:48 +020021Setup jenkins slave.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020022
23``jenkins.job_builder``
24-----------------------
25
Ales Komareke5a1ed62016-08-27 12:02:48 +020026Setup jenkins job builder.
27
28``jenkins.client``
29------------------
30
31Setup jenkins client, works with Salt 2016.3+, supports pipeline workflow projects only now.
32
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020033
34Available metadata
35==================
36
37.. contents::
38 :local:
39
40``metadata.jenkins.master.single``
41----------------------------------
42
43Setup single-node master
44
45
46``metadata.jenkins.slave.single``
47---------------------------------
48
49Setup Jenkins slave
50
Ales Komareke5a1ed62016-08-27 12:02:48 +020051Sample pillars
52==============
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020053
Ales Komarek4c0bab12016-01-22 12:10:50 +010054Jenkins master
Ales Komareke5a1ed62016-08-27 12:02:48 +020055--------------
56
57Simple master with reverse proxy
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020058
59.. code-block:: yaml
60
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020061 nginx:
62 server:
63 site:
64 jenkins:
65 enabled: true
66 type: nginx_proxy
67 name: jenkins
68 proxy:
69 host: 127.0.0.1
70 port: 8080
71 protocol: http
72 host:
73 name: jenkins.example.com
74 port: 80
75 jenkins:
76 master:
77 mode: EXCLUSIVE
Filip Pytloun52b9c2c2016-01-28 13:45:57 +010078 # Do not manage config.xml from Salt, use UI instead
79 no_config: true
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020080 slaves:
81 - name: slave01
82 label: pbuilder
83 executors: 2
84 - name: slave02
85 label: image_builder
86 mode: EXCLUSIVE
87 executors: 2
88 views:
89 - name: "Package builds"
90 regex: "debian-build-.*"
91 - name: "Contrail builds"
92 regex: "contrail-build-.*"
93 - name: "Aptly"
94 regex: "aptly-.*"
95 plugins:
96 - name: slack
97 - name: extended-choice-parameter
98 - name: rebuild
99 - name: test-stability
100
Ales Komarekaf967ee2016-08-31 19:38:50 +0200101Jenkins with experimental plugin source support
102
103.. code-block:: yaml
104
105 jenkins:
106 master:
107 enabled: true
108 update_site_url: 'http://updates.jenkins-ci.org/experimental/update-center.json'
109
110
Ales Komareke5a1ed62016-08-27 12:02:48 +0200111Agent (former slave)
112--------------------
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200113
114.. code-block:: yaml
115
Ales Komarek4c0bab12016-01-22 12:10:50 +0100116 jenkins:
117 slave:
118 master:
119 host: jenkins.example.com
120 port: 80
Michael Kutý37a35952016-06-10 23:51:36 +0200121 protocol: http
Ales Komarek4c0bab12016-01-22 12:10:50 +0100122 user:
123 name: jenkins_slave
124 password: dexiech6AepohthaiHook2iesh7ol5ook4Ov3leid3yek6daid2ooNg3Ee2oKeYo
125 gpg:
126 keypair_id: A76882D3
127 public_key: |
128 -----BEGIN PGP PUBLIC KEY BLOCK-----
129 ...
130 private_key: |
131 -----BEGIN PGP PRIVATE KEY BLOCK-----
132 ...
Ales Komarekaf967ee2016-08-31 19:38:50 +0200133
Ales Komareke5a1ed62016-08-27 12:02:48 +0200134Client
135------
136
137Simple client with workflow job definition
138
139.. code-block:: yaml
140
141 jenkins:
142 client:
143 master:
144 host: jenkins.example.com
145 port: 80
146 protocol: http
147 job:
148 jobname:
149 type: workflow
150 param:
151 bool_param:
152 type: boolean
153 description: true/false
154 default: true
155 string_param:
156 type: string
157 description: 1 liner
158 default: default_string
159 text_param:
160 type: text
161 description: multi-liner
162 default: default_text
Filip Pytlounebd4d172016-09-01 14:23:20 +0200163 jobname_scm:
164 type: workflow-scm
165 concurrent: false
166 scm:
167 type: git
168 url: https://github.com/jenkinsci/docker.git
169 branch: master
170 script: Jenkinsfile
171 github:
172 url: https://github.com/jenkinsci/docker
173 name: "Jenkins Docker Image"
174 trigger:
175 github:
176 pollscm:
177 spec: "H/15 * * * *"
178 reverse:
179 projects:
180 - test1
181 - test2
182 state: SUCCESS
183 param:
184 bool_param:
185 type: boolean
186 description: true/false
187 default: true
188 string_param:
189 type: string
190 description: 1 liner
191 default: default_string
192 text_param:
193 type: text
194 description: multi-liner
195 default: default_text
Ales Komareke5a1ed62016-08-27 12:02:48 +0200196
Ales Komarekdaf31f72016-08-29 11:00:13 +0200197Inline Groovy script samples
Ales Komareke5a1ed62016-08-27 12:02:48 +0200198
199.. code-block:: yaml
200
201 jenkins:
202 client:
203 job:
204 test_workflow_jenkins_simple:
205 type: workflow
206 display_name: Test jenkins simple workflow
Ales Komarek5b672fd2016-08-29 16:05:03 +0200207 script:
208 content: |
209 node {
210 stage 'Stage 1'
211 echo 'Hello World 1'
212 stage 'Stage 2'
213 echo 'Hello World 2'
214 }
Ales Komareke5a1ed62016-08-27 12:02:48 +0200215 test_workflow_jenkins_input:
216 type: workflow
217 display_name: Test jenkins workflow inputs
Ales Komarek5b672fd2016-08-29 16:05:03 +0200218 script:
219 content: |
220 node {
221 stage 'Enter string'
222 input message: 'Enter job parameters', ok: 'OK', parameters: [
223 string(defaultValue: 'default', description: 'Enter a string.', name: 'string'),
224 ]
225 stage 'Enter boolean'
226 input message: 'Enter job parameters', ok: 'OK', parameters: [
227 booleanParam(defaultValue: false, description: 'Select boolean.', name: 'Bool'),
228 ]
229 stage 'Enter text'
230 input message: 'Enter job parameters', ok: 'OK', parameters: [
231 text(defaultValue: '', description: 'Enter multiline', name: 'Multiline')
232 ]
233 }
Ales Komareke5a1ed62016-08-27 12:02:48 +0200234
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200235
Ales Komarekdaf31f72016-08-29 11:00:13 +0200236GIT controlled groovy script samples
237
238.. code-block:: yaml
239
240 jenkins:
241 client:
242 source:
Ales Komarek5b672fd2016-08-29 16:05:03 +0200243 base:
244 engine: git
245 address: repo_url
246 branch: branch
247 domain:
248 engine: git
249 address: domain_url
250 branch: branch
Ales Komarekdaf31f72016-08-29 11:00:13 +0200251 job:
252 test_workflow_jenkins_simple:
253 type: workflow
254 display_name: Test jenkins simple workflow
Ales Komarek5b672fd2016-08-29 16:05:03 +0200255 param:
256 bool_param:
257 type: boolean
258 description: true/false
259 default: true
260 script:
261 repository: base
262 file: workflows/test_workflow_jenkins_simple.groovy
Ales Komarekdaf31f72016-08-29 11:00:13 +0200263 test_workflow_jenkins_input:
264 type: workflow
265 display_name: Test jenkins workflow inputs
Ales Komarek5b672fd2016-08-29 16:05:03 +0200266 script:
267 repository: domain
268 file: workflows/test_workflow_jenkins_input.groovy
269 test_workflow_jenkins_input_jenkinsfile:
270 type: workflow
271 display_name: Test jenkins workflow inputs (jenknisfile)
272 script:
273 repository: domain
274 file: workflows/test_workflow_jenkins_input/Jenkinsfile
Ales Komarekdaf31f72016-08-29 11:00:13 +0200275
Ales Komarek5b672fd2016-08-29 16:05:03 +0200276GIT controlled groovy script with shared libraries
277
278.. code-block:: yaml
279
280 jenkins:
281 client:
282 source:
283 base:
284 engine: git
285 address: repo_url
286 branch: branch
287 domain:
288 engine: git
289 address: domain_url
290 branch: branch
291 job:
292 test_workflow_jenkins_simple:
293 type: workflow
294 display_name: Test jenkins simple workflow
295 param:
296 bool_param:
297 type: boolean
298 description: true/false
299 default: true
300 script:
301 repository: base
302 file: workflows/test_workflow_jenkins_simple.groovy
303 libs:
304 - repository: base
305 file: macros/cookiecutter.groovy
306 - repository: base
307 file: macros/git.groovy
Ales Komarekdaf31f72016-08-29 11:00:13 +0200308
Jakub Josef120714d2017-02-09 16:29:18 +0100309Setting job max builds to keep (amount of last builds stored on Jenkins master)
310
311.. code-block:: yaml
312
313 jenkins:
314 client:
315 job:
316 my-amazing-job:
317 type: workflow
318 discard:
319 build:
320 keep_num: 5
321 keep_days: 5
322 artifact:
323 keep_num: 6
324 keep_days: 6
325
Jakub Josef2a7739b2017-01-24 18:33:44 +0100326Purging undefined jobs from Jenkins
327
328.. code-block:: yaml
329
330 jenkins:
331 client:
332 purge_jobs: true
333
Jakub Josef10b4e102017-01-05 18:18:41 +0100334Plugins management from client
335
336.. code-block:: yaml
337
338
339 jenkins:
340 client:
341 plugin:
342 swarm:
343 restart: false
344 hipchat:
345 enabled: false
346 restart: true
347
Jakub Josef063a7532017-01-11 15:48:01 +0100348LDAP configuration (depends on LDAP plugin)
349
350.. code-block:: yaml
351
352 jenkins:
353 client:
354 security:
355 ldap:
356 server: 1.2.3.4
357 root_dn: dc=foo,dc=com
358 user_search_base: cn=users,cn=accounts
359 manager_dn: ""
360 manager_password: password
361 user_search: ""
362 group_search_base: ""
363 inhibit_infer_root_dn: false
364
365
366Matrix configuration (depends on auth-matrix plugin)
367
368.. code-block:: yaml
369
370 jenkins:
371 client:
372 security:
373 matrix:
Jakub Josef0ee470e2017-01-17 11:46:58 +0100374 # set true for use ProjectMatrixAuthStrategy instead of GlobalMatrixAuthStrategy
375 project_based: false
Jakub Josef063a7532017-01-11 15:48:01 +0100376 permissions:
377 Jenkins:
378 # administrator access
379 ADMINISTER:
380 - admin
381 # read access (anonymous too)
382 READ:
383 - anonymous
384 - user1
385 - user2
386 # agents permissions
387 MasterComputer:
388 BUILD:
389 - user3
390 # jobs permissions
391 hudson:
392 model:
393 Item:
394 BUILD:
395 - user4
396
397`Common matrix strategies <https://github.com/arbabnazar/configuration/blob/c08a5eaf4e04a68d2481375502a926517097b253/playbooks/roles/tools_jenkins/templates/projectBasedMatrixSecurity.groovy.j2>`_
398
Jakub Josef7bb17ab2017-01-12 14:52:53 +0100399Views enforcing from client
400
401.. code-block:: yaml
402
403 jenkins:
404 client:
405 view:
406 my-list-view:
407 enabled: true
408 type: ListView
409 include_regex: ".\*."
410 my-view:
411 # set false to disable
412 enabled: true
413 type: MyView
414
415View specific params:
416
417- include_regex for ListView
418
Jakub Josef063a7532017-01-11 15:48:01 +0100419
Jakub Josef123be7a2016-12-12 16:02:36 +0100420Credentials enforcing from client
421
422.. code-block:: yaml
423
424 jenkins:
425 client:
426 credential:
427 cred_first:
428 username: admin
429 password: password
430 cred_second:
431 username: salt
432 password: password
433 cred_with_key:
434 username: admin
435 key: SOMESSHKEY
436
437Users enforcing from client
438
439.. code-block:: yaml
440
441 jenkins:
442 client:
443 user:
444 admin:
445 password: admin_password
446 admin: true
447 user01:
448 password: user_password
449
450Node enforcing from client using JNLP launcher
451
452.. code-block:: yaml
453
454 jenkins:
455 client:
456 node:
457 node01:
458 remote_home: /remote/home/path
459 desc: node-description
460 num_executors: 1
461 node_mode: Normal
462 ret_strategy: Always
Jakub Josef98123ab2016-12-14 14:05:01 +0100463 labels:
464 - example
465 - label
Jakub Josef123be7a2016-12-12 16:02:36 +0100466 launcher:
467 type: jnlp
468
469Node enforcing from client using SSH launcher
470
471.. code-block:: yaml
472
473 jenkins:
474 client:
475 node:
476 node01:
477 remote_home: /remote/home/path
478 desc: node-description
479 num_executors: 1
480 node_mode: Normal
481 ret_strategy: Always
Jakub Josef98123ab2016-12-14 14:05:01 +0100482 labels:
483 - example
484 - label
Jakub Josef123be7a2016-12-12 16:02:36 +0100485 launcher:
486 type: ssh
487 host: test-launcher
488 port: 22
489 username: launcher-user
490 password: launcher-pass
491
492Setting node labels
493
494.. code-block:: yaml
495
496 jenkins:
497 client:
498 label:
499 node-name:
500 lbl_text: label-offline
501 append: false # set true for label append instead of replace
502
Jakub Josef60cc9d22017-01-18 12:02:14 +0100503SMTP server settings from master
Jakub Josefd8e04292016-11-28 18:02:27 +0100504
505.. code-block:: yaml
506
507 jenkins:
508 master:
509 email:
510 engine: "smtp"
511 host: "smtp.domain.com"
512 user: "user@domain.cz"
513 password: "smtp-password"
514 port: 25
515
Jakub Josef60cc9d22017-01-18 12:02:14 +0100516SMTP server settings from client
517
518.. code-block:: yaml
519
520 jenkins:
521 client:
522 smtp:
523 host: "smtp.domain.com"
524 username: "user@domain.cz"
525 password: "smtp-password"
526 port: 25
527 ssl: false
528 reply_to: reply_to@address.com
529
Jakub Josefd8e04292016-11-28 18:02:27 +0100530Jenkins script approvals
531
532.. code-block:: yaml
533
534 jenkins:
535 master:
536 approved_scripts:
537 - method groovy.json.JsonSlurperClassic parseText java.lang.String
538
Jakub Josefa6d4c832017-01-19 14:06:12 +0100539Slack plugin configuration
540
541.. code-block:: yaml
542
543 jenkins:
544 client:
545 slack:
546 team_domain: example.com
547 token: slack-token
548 room: slack-room
549 token_credential_id: cred_id
550 send_as: Some slack user
551
Jakub Josefd8e04292016-11-28 18:02:27 +0100552
Jakub Josef123be7a2016-12-12 16:02:36 +0100553Users enforcing from master
Jakub Josefd8e04292016-11-28 18:02:27 +0100554
555.. code-block:: yaml
556
557 jenkins:
558 user:
559 admin:
560 api_token: xxxxxxxxxx
561 password: admin_password
562 email: admin@domain.com
563 user01:
564 api_token: xxxxxxxxxx
565 password: user_password
566 email: user01@domain.com
567
Ales Komarek4c0bab12016-01-22 12:10:50 +0100568Usage
569=====
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200570
Ales Komarek4c0bab12016-01-22 12:10:50 +0100571Generate password hash:
572
573.. code-block:: bash
574
575 echo -n "salt{plainpassword}" | openssl dgst -sha256
576
577Place in the configuration ``salt:hashpassword``.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200578
579Read more
580=========
581
582* https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins
Filip Pytlounadf72fa2017-02-02 13:02:03 +0100583
584Documentation and Bugs
585======================
586
587To learn how to install and update salt-formulas, consult the documentation
588available online at:
589
590 http://salt-formulas.readthedocs.io/
591
592In the unfortunate event that bugs are discovered, they should be reported to
593the appropriate issue tracker. Use Github issue tracker for specific salt
594formula:
595
596 https://github.com/salt-formulas/salt-formula-jenkins/issues
597
598For feature requests, bug reports or blueprints affecting entire ecosystem,
599use Launchpad salt-formulas project:
600
601 https://launchpad.net/salt-formulas
602
603You can also join salt-formulas-users team and subscribe to mailing list:
604
605 https://launchpad.net/~salt-formulas-users
606
607Developers wishing to work on the salt-formulas projects should always base
608their work on master branch and submit pull request against specific formula.
609
610 https://github.com/salt-formulas/salt-formula-jenkins
611
612Any questions or feedback is always welcome so feel free to join our IRC
613channel:
614
615 #salt-formulas @ irc.freenode.net