blob: 3438cb21108fab299f6f2c73256f757d6b5544c0 [file] [log] [blame]
Ales Komarekffe8bb22017-02-09 11:10:16 +01001===============
2Jenkins formula
3===============
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +02004
Ales Komarekffe8bb22017-02-09 11:10:16 +01005Jenkins is an application that monitors executions of repeated jobs, such as
6building a software project or jobs run by cron.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +02007
Ales Komarekffe8bb22017-02-09 11:10:16 +01008Setup jenkins client, works with Salt 2016.3+, supports pipeline workflow
9projects only now.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020010
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020011
Ales Komareke5a1ed62016-08-27 12:02:48 +020012Sample pillars
13==============
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020014
Ales Komarekffe8bb22017-02-09 11:10:16 +010015Master role
16-----------
Ales Komareke5a1ed62016-08-27 12:02:48 +020017
18Simple master with reverse proxy
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020019
20.. code-block:: yaml
21
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020022 nginx:
23 server:
24 site:
25 jenkins:
26 enabled: true
27 type: nginx_proxy
28 name: jenkins
29 proxy:
30 host: 127.0.0.1
31 port: 8080
32 protocol: http
33 host:
34 name: jenkins.example.com
35 port: 80
36 jenkins:
37 master:
38 mode: EXCLUSIVE
Filip Pytloun52b9c2c2016-01-28 13:45:57 +010039 # Do not manage config.xml from Salt, use UI instead
40 no_config: true
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020041 slaves:
42 - name: slave01
43 label: pbuilder
44 executors: 2
45 - name: slave02
46 label: image_builder
47 mode: EXCLUSIVE
48 executors: 2
49 views:
50 - name: "Package builds"
51 regex: "debian-build-.*"
52 - name: "Contrail builds"
53 regex: "contrail-build-.*"
54 - name: "Aptly"
55 regex: "aptly-.*"
56 plugins:
57 - name: slack
58 - name: extended-choice-parameter
59 - name: rebuild
60 - name: test-stability
61
Ales Komarekffe8bb22017-02-09 11:10:16 +010062Jenkins master with experimental plugin source support
Ales Komarekaf967ee2016-08-31 19:38:50 +020063
64.. code-block:: yaml
65
66 jenkins:
67 master:
68 enabled: true
69 update_site_url: 'http://updates.jenkins-ci.org/experimental/update-center.json'
70
Ales Komarekffe8bb22017-02-09 11:10:16 +010071SMTP server settings
Ales Komarekaf967ee2016-08-31 19:38:50 +020072
Ales Komarekffe8bb22017-02-09 11:10:16 +010073.. code-block:: yaml
74
75 jenkins:
76 master:
77 email:
78 engine: "smtp"
79 host: "smtp.domain.com"
80 user: "user@domain.cz"
81 password: "smtp-password"
82 port: 25
83
84Script approvals
85
86.. code-block:: yaml
87
88 jenkins:
89 master:
90 approved_scripts:
91 - method groovy.json.JsonSlurperClassic parseText java.lang.String
92
93User enforcement
94
95.. code-block:: yaml
96
97 jenkins:
98 master:
99 user:
100 admin:
101 api_token: xxxxxxxxxx
102 password: admin_password
103 email: admin@domain.com
104 user01:
105 api_token: xxxxxxxxxx
106 password: user_password
107 email: user01@domain.com
108
109
110Agent (slave) role
111------------------
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200112
113.. code-block:: yaml
114
Ales Komarek4c0bab12016-01-22 12:10:50 +0100115 jenkins:
116 slave:
117 master:
118 host: jenkins.example.com
119 port: 80
Michael Kutý37a35952016-06-10 23:51:36 +0200120 protocol: http
Ales Komarek4c0bab12016-01-22 12:10:50 +0100121 user:
122 name: jenkins_slave
123 password: dexiech6AepohthaiHook2iesh7ol5ook4Ov3leid3yek6daid2ooNg3Ee2oKeYo
124 gpg:
125 keypair_id: A76882D3
126 public_key: |
127 -----BEGIN PGP PUBLIC KEY BLOCK-----
128 ...
129 private_key: |
130 -----BEGIN PGP PRIVATE KEY BLOCK-----
131 ...
Ales Komarekaf967ee2016-08-31 19:38:50 +0200132
Ales Komarekffe8bb22017-02-09 11:10:16 +0100133
134Client role
135-----------
Ales Komareke5a1ed62016-08-27 12:02:48 +0200136
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:
Tomáš Kukrála9cf2c62017-03-04 11:25:20 +0100175 timer:
176 spec: "H H * * *"
Filip Pytlounebd4d172016-09-01 14:23:20 +0200177 github:
178 pollscm:
179 spec: "H/15 * * * *"
180 reverse:
181 projects:
182 - test1
183 - test2
184 state: SUCCESS
185 param:
186 bool_param:
187 type: boolean
188 description: true/false
189 default: true
190 string_param:
191 type: string
192 description: 1 liner
193 default: default_string
194 text_param:
195 type: text
196 description: multi-liner
197 default: default_text
Ales Komareke5a1ed62016-08-27 12:02:48 +0200198
Ales Komarekffe8bb22017-02-09 11:10:16 +0100199Inline Groovy scripts
Ales Komareke5a1ed62016-08-27 12:02:48 +0200200
201.. code-block:: yaml
202
203 jenkins:
204 client:
205 job:
206 test_workflow_jenkins_simple:
207 type: workflow
208 display_name: Test jenkins simple workflow
Ales Komarek5b672fd2016-08-29 16:05:03 +0200209 script:
210 content: |
211 node {
212 stage 'Stage 1'
213 echo 'Hello World 1'
214 stage 'Stage 2'
215 echo 'Hello World 2'
216 }
Ales Komareke5a1ed62016-08-27 12:02:48 +0200217 test_workflow_jenkins_input:
218 type: workflow
219 display_name: Test jenkins workflow inputs
Ales Komarek5b672fd2016-08-29 16:05:03 +0200220 script:
221 content: |
222 node {
223 stage 'Enter string'
224 input message: 'Enter job parameters', ok: 'OK', parameters: [
225 string(defaultValue: 'default', description: 'Enter a string.', name: 'string'),
226 ]
227 stage 'Enter boolean'
228 input message: 'Enter job parameters', ok: 'OK', parameters: [
229 booleanParam(defaultValue: false, description: 'Select boolean.', name: 'Bool'),
230 ]
231 stage 'Enter text'
232 input message: 'Enter job parameters', ok: 'OK', parameters: [
233 text(defaultValue: '', description: 'Enter multiline', name: 'Multiline')
234 ]
235 }
Ales Komareke5a1ed62016-08-27 12:02:48 +0200236
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200237
Ales Komarekffe8bb22017-02-09 11:10:16 +0100238GIT controlled groovy scripts
Ales Komarekdaf31f72016-08-29 11:00:13 +0200239
240.. code-block:: yaml
241
242 jenkins:
243 client:
244 source:
Ales Komarek5b672fd2016-08-29 16:05:03 +0200245 base:
246 engine: git
247 address: repo_url
248 branch: branch
249 domain:
250 engine: git
251 address: domain_url
252 branch: branch
Ales Komarekdaf31f72016-08-29 11:00:13 +0200253 job:
254 test_workflow_jenkins_simple:
255 type: workflow
256 display_name: Test jenkins simple workflow
Ales Komarek5b672fd2016-08-29 16:05:03 +0200257 param:
258 bool_param:
259 type: boolean
260 description: true/false
261 default: true
262 script:
263 repository: base
264 file: workflows/test_workflow_jenkins_simple.groovy
Ales Komarekdaf31f72016-08-29 11:00:13 +0200265 test_workflow_jenkins_input:
266 type: workflow
267 display_name: Test jenkins workflow inputs
Ales Komarek5b672fd2016-08-29 16:05:03 +0200268 script:
269 repository: domain
270 file: workflows/test_workflow_jenkins_input.groovy
271 test_workflow_jenkins_input_jenkinsfile:
272 type: workflow
273 display_name: Test jenkins workflow inputs (jenknisfile)
274 script:
275 repository: domain
276 file: workflows/test_workflow_jenkins_input/Jenkinsfile
Ales Komarekdaf31f72016-08-29 11:00:13 +0200277
Ales Komarek5b672fd2016-08-29 16:05:03 +0200278GIT controlled groovy script with shared libraries
279
280.. code-block:: yaml
281
282 jenkins:
283 client:
284 source:
285 base:
286 engine: git
287 address: repo_url
288 branch: branch
289 domain:
290 engine: git
291 address: domain_url
292 branch: branch
293 job:
294 test_workflow_jenkins_simple:
295 type: workflow
296 display_name: Test jenkins simple workflow
297 param:
298 bool_param:
299 type: boolean
300 description: true/false
301 default: true
302 script:
303 repository: base
304 file: workflows/test_workflow_jenkins_simple.groovy
305 libs:
306 - repository: base
307 file: macros/cookiecutter.groovy
308 - repository: base
309 file: macros/git.groovy
Ales Komarekdaf31f72016-08-29 11:00:13 +0200310
Jakub Josef120714d2017-02-09 16:29:18 +0100311Setting job max builds to keep (amount of last builds stored on Jenkins master)
312
313.. code-block:: yaml
314
315 jenkins:
316 client:
317 job:
318 my-amazing-job:
319 type: workflow
320 discard:
321 build:
322 keep_num: 5
323 keep_days: 5
324 artifact:
325 keep_num: 6
326 keep_days: 6
327
Ales Komarekffe8bb22017-02-09 11:10:16 +0100328
329Using job templates in similar way as in jjb. For now just 1 defined param is
330supported.
331
332.. code-block:: yaml
333
334 jenkins:
335 client:
336 job_template:
337 test_workflow_template:
338 name: test-{{formula}}-workflow
339 template:
340 type: workflow
341 display_name: Test jenkins {{name}} workflow
342 param:
343 repo_param:
344 type: string
345 default: repo/{{formula}}
346 script:
347 repository: base
348 file: workflows/test_formula_workflow.groovy
349 param:
350 formula:
351 - aodh
352 - linux
353 - openssh
354
355Interpolating parameters for job templates.
356
Filip Pytloun83129fc2017-02-23 10:07:32 +0100357.. code-block:: yaml
358
Ales Komarekffe8bb22017-02-09 11:10:16 +0100359 _param:
360 salt_formulas:
361 - aodh
362 - git
363 - nova
364 - xorg
365 jenkins:
366 client:
367 job_template:
368 test_workflow_template:
369 name: test-{{formula}}-workflow
370 template:
371 ...
372 param:
373 formula: ${_param:salt_formulas}
374
Filip Pytloun83129fc2017-02-23 10:07:32 +0100375Or simply define multiple jobs and it's parameters to replace from template:
376
377.. code-block:: yaml
378
379 jenkins:
380 client:
381 job_template:
382 test_workflow_template:
383 name: test-{{name}}-{{myparam}}
384 template:
385 ...
386 jobs:
387 - name: firstjob
388 myparam: dummy
389 - name: secondjob
390 myparam: dummyaswell
Ales Komarekffe8bb22017-02-09 11:10:16 +0100391
Jakub Josef2a7739b2017-01-24 18:33:44 +0100392Purging undefined jobs from Jenkins
393
394.. code-block:: yaml
395
396 jenkins:
397 client:
398 purge_jobs: true
Ales Komarekffe8bb22017-02-09 11:10:16 +0100399 job:
400 my-amazing-job:
401 type: workflow
Jakub Josef2a7739b2017-01-24 18:33:44 +0100402
Jakub Josef10b4e102017-01-05 18:18:41 +0100403Plugins management from client
404
405.. code-block:: yaml
406
407
408 jenkins:
409 client:
410 plugin:
411 swarm:
412 restart: false
413 hipchat:
414 enabled: false
415 restart: true
416
Jakub Josef063a7532017-01-11 15:48:01 +0100417LDAP configuration (depends on LDAP plugin)
418
419.. code-block:: yaml
420
421 jenkins:
422 client:
423 security:
424 ldap:
425 server: 1.2.3.4
426 root_dn: dc=foo,dc=com
427 user_search_base: cn=users,cn=accounts
428 manager_dn: ""
429 manager_password: password
430 user_search: ""
431 group_search_base: ""
432 inhibit_infer_root_dn: false
433
434
435Matrix configuration (depends on auth-matrix plugin)
436
437.. code-block:: yaml
438
439 jenkins:
440 client:
441 security:
442 matrix:
Jakub Josef0ee470e2017-01-17 11:46:58 +0100443 # set true for use ProjectMatrixAuthStrategy instead of GlobalMatrixAuthStrategy
444 project_based: false
Jakub Josef063a7532017-01-11 15:48:01 +0100445 permissions:
446 Jenkins:
447 # administrator access
448 ADMINISTER:
449 - admin
450 # read access (anonymous too)
451 READ:
452 - anonymous
453 - user1
454 - user2
455 # agents permissions
456 MasterComputer:
457 BUILD:
458 - user3
459 # jobs permissions
460 hudson:
461 model:
462 Item:
463 BUILD:
464 - user4
465
466`Common matrix strategies <https://github.com/arbabnazar/configuration/blob/c08a5eaf4e04a68d2481375502a926517097b253/playbooks/roles/tools_jenkins/templates/projectBasedMatrixSecurity.groovy.j2>`_
467
Jakub Josef7bb17ab2017-01-12 14:52:53 +0100468Views enforcing from client
469
470.. code-block:: yaml
471
472 jenkins:
473 client:
474 view:
475 my-list-view:
476 enabled: true
477 type: ListView
478 include_regex: ".\*."
479 my-view:
480 # set false to disable
481 enabled: true
482 type: MyView
483
484View specific params:
485
486- include_regex for ListView
487
Jakub Josef063a7532017-01-11 15:48:01 +0100488
Jakub Josef123be7a2016-12-12 16:02:36 +0100489Credentials enforcing from client
490
491.. code-block:: yaml
492
493 jenkins:
494 client:
495 credential:
496 cred_first:
497 username: admin
498 password: password
499 cred_second:
500 username: salt
501 password: password
502 cred_with_key:
503 username: admin
504 key: SOMESSHKEY
505
506Users enforcing from client
507
508.. code-block:: yaml
509
510 jenkins:
511 client:
512 user:
513 admin:
514 password: admin_password
515 admin: true
516 user01:
517 password: user_password
518
519Node enforcing from client using JNLP launcher
520
521.. code-block:: yaml
522
523 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100524 client:
525 node:
526 node01:
527 remote_home: /remote/home/path
528 desc: node-description
529 num_executors: 1
530 node_mode: Normal
531 ret_strategy: Always
532 labels:
533 - example
534 - label
535 launcher:
536 type: jnlp
Jakub Josef123be7a2016-12-12 16:02:36 +0100537
538Node enforcing from client using SSH launcher
539
540.. code-block:: yaml
541
542 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100543 client:
544 node:
545 node01:
546 remote_home: /remote/home/path
547 desc: node-description
548 num_executors: 1
549 node_mode: Normal
550 ret_strategy: Always
551 labels:
552 - example
553 - label
554 launcher:
555 type: ssh
556 host: test-launcher
557 port: 22
558 username: launcher-user
559 password: launcher-pass
Jakub Josef123be7a2016-12-12 16:02:36 +0100560
561Setting node labels
562
563.. code-block:: yaml
564
565 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100566 client:
567 label:
568 node-name:
569 lbl_text: label-offline
570 append: false # set true for label append instead of replace
Jakub Josefd8e04292016-11-28 18:02:27 +0100571
Jakub Josef60cc9d22017-01-18 12:02:14 +0100572SMTP server settings from client
573
574.. code-block:: yaml
575
576 jenkins:
577 client:
578 smtp:
579 host: "smtp.domain.com"
580 username: "user@domain.cz"
581 password: "smtp-password"
582 port: 25
583 ssl: false
584 reply_to: reply_to@address.com
585
Jakub Josefa6d4c832017-01-19 14:06:12 +0100586Slack plugin configuration
587
588.. code-block:: yaml
589
590 jenkins:
591 client:
592 slack:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100593 team_domain: example.com
594 token: slack-token
595 room: slack-room
Jakub Josef6e0cda92017-02-14 18:01:58 +0100596 token_credential_id: cred_id
Ales Komarekffe8bb22017-02-09 11:10:16 +0100597 send_as: Some slack user
Jakub Josefa6d4c832017-01-19 14:06:12 +0100598
Jakub Josef6e0cda92017-02-14 18:01:58 +0100599Pipeline global libraries setup
600
601.. code-block:: yaml
602
603 jenkins:
604 client:
605 lib:
606 my-pipeline-library:
607 enabled: true
608 url: https://path-to-my-library
609 credential_id: github
610 branch: master # optional, default master
611 implicit: true # optional default true
Jakub Josefd8e04292016-11-28 18:02:27 +0100612
Ales Komarek4c0bab12016-01-22 12:10:50 +0100613Usage
614=====
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200615
Ales Komarek4c0bab12016-01-22 12:10:50 +0100616Generate password hash:
617
618.. code-block:: bash
619
620 echo -n "salt{plainpassword}" | openssl dgst -sha256
621
622Place in the configuration ``salt:hashpassword``.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200623
Ales Komarekffe8bb22017-02-09 11:10:16 +0100624
625External links
626==============
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200627
628* https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins
Filip Pytlounadf72fa2017-02-02 13:02:03 +0100629
Ales Komarekffe8bb22017-02-09 11:10:16 +0100630
Filip Pytlounadf72fa2017-02-02 13:02:03 +0100631Documentation and Bugs
632======================
633
634To learn how to install and update salt-formulas, consult the documentation
635available online at:
636
637 http://salt-formulas.readthedocs.io/
638
639In the unfortunate event that bugs are discovered, they should be reported to
640the appropriate issue tracker. Use Github issue tracker for specific salt
641formula:
642
643 https://github.com/salt-formulas/salt-formula-jenkins/issues
644
645For feature requests, bug reports or blueprints affecting entire ecosystem,
646use Launchpad salt-formulas project:
647
648 https://launchpad.net/salt-formulas
649
650You can also join salt-formulas-users team and subscribe to mailing list:
651
652 https://launchpad.net/~salt-formulas-users
653
654Developers wishing to work on the salt-formulas projects should always base
655their work on master branch and submit pull request against specific formula.
656
657 https://github.com/salt-formulas/salt-formula-jenkins
658
659Any questions or feedback is always welcome so feel free to join our IRC
660channel:
661
662 #salt-formulas @ irc.freenode.net