blob: fe3421dc32a2208129e0bccc4ede33f6f61c269d [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:
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 Komarekffe8bb22017-02-09 11:10:16 +0100197Inline Groovy scripts
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 Komarekffe8bb22017-02-09 11:10:16 +0100236GIT controlled groovy scripts
Ales Komarekdaf31f72016-08-29 11:00:13 +0200237
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
Ales Komarekffe8bb22017-02-09 11:10:16 +0100326
327Using job templates in similar way as in jjb. For now just 1 defined param is
328supported.
329
330.. code-block:: yaml
331
332 jenkins:
333 client:
334 job_template:
335 test_workflow_template:
336 name: test-{{formula}}-workflow
337 template:
338 type: workflow
339 display_name: Test jenkins {{name}} workflow
340 param:
341 repo_param:
342 type: string
343 default: repo/{{formula}}
344 script:
345 repository: base
346 file: workflows/test_formula_workflow.groovy
347 param:
348 formula:
349 - aodh
350 - linux
351 - openssh
352
353Interpolating parameters for job templates.
354
355 _param:
356 salt_formulas:
357 - aodh
358 - git
359 - nova
360 - xorg
361 jenkins:
362 client:
363 job_template:
364 test_workflow_template:
365 name: test-{{formula}}-workflow
366 template:
367 ...
368 param:
369 formula: ${_param:salt_formulas}
370
371
Jakub Josef2a7739b2017-01-24 18:33:44 +0100372Purging undefined jobs from Jenkins
373
374.. code-block:: yaml
375
376 jenkins:
377 client:
378 purge_jobs: true
Ales Komarekffe8bb22017-02-09 11:10:16 +0100379 job:
380 my-amazing-job:
381 type: workflow
Jakub Josef2a7739b2017-01-24 18:33:44 +0100382
Jakub Josef10b4e102017-01-05 18:18:41 +0100383Plugins management from client
384
385.. code-block:: yaml
386
387
388 jenkins:
389 client:
390 plugin:
391 swarm:
392 restart: false
393 hipchat:
394 enabled: false
395 restart: true
396
Jakub Josef063a7532017-01-11 15:48:01 +0100397LDAP configuration (depends on LDAP plugin)
398
399.. code-block:: yaml
400
401 jenkins:
402 client:
403 security:
404 ldap:
405 server: 1.2.3.4
406 root_dn: dc=foo,dc=com
407 user_search_base: cn=users,cn=accounts
408 manager_dn: ""
409 manager_password: password
410 user_search: ""
411 group_search_base: ""
412 inhibit_infer_root_dn: false
413
414
415Matrix configuration (depends on auth-matrix plugin)
416
417.. code-block:: yaml
418
419 jenkins:
420 client:
421 security:
422 matrix:
Jakub Josef0ee470e2017-01-17 11:46:58 +0100423 # set true for use ProjectMatrixAuthStrategy instead of GlobalMatrixAuthStrategy
424 project_based: false
Jakub Josef063a7532017-01-11 15:48:01 +0100425 permissions:
426 Jenkins:
427 # administrator access
428 ADMINISTER:
429 - admin
430 # read access (anonymous too)
431 READ:
432 - anonymous
433 - user1
434 - user2
435 # agents permissions
436 MasterComputer:
437 BUILD:
438 - user3
439 # jobs permissions
440 hudson:
441 model:
442 Item:
443 BUILD:
444 - user4
445
446`Common matrix strategies <https://github.com/arbabnazar/configuration/blob/c08a5eaf4e04a68d2481375502a926517097b253/playbooks/roles/tools_jenkins/templates/projectBasedMatrixSecurity.groovy.j2>`_
447
Jakub Josef7bb17ab2017-01-12 14:52:53 +0100448Views enforcing from client
449
450.. code-block:: yaml
451
452 jenkins:
453 client:
454 view:
455 my-list-view:
456 enabled: true
457 type: ListView
458 include_regex: ".\*."
459 my-view:
460 # set false to disable
461 enabled: true
462 type: MyView
463
464View specific params:
465
466- include_regex for ListView
467
Jakub Josef063a7532017-01-11 15:48:01 +0100468
Jakub Josef123be7a2016-12-12 16:02:36 +0100469Credentials enforcing from client
470
471.. code-block:: yaml
472
473 jenkins:
474 client:
475 credential:
476 cred_first:
477 username: admin
478 password: password
479 cred_second:
480 username: salt
481 password: password
482 cred_with_key:
483 username: admin
484 key: SOMESSHKEY
485
486Users enforcing from client
487
488.. code-block:: yaml
489
490 jenkins:
491 client:
492 user:
493 admin:
494 password: admin_password
495 admin: true
496 user01:
497 password: user_password
498
499Node enforcing from client using JNLP launcher
500
501.. code-block:: yaml
502
503 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100504 client:
505 node:
506 node01:
507 remote_home: /remote/home/path
508 desc: node-description
509 num_executors: 1
510 node_mode: Normal
511 ret_strategy: Always
512 labels:
513 - example
514 - label
515 launcher:
516 type: jnlp
Jakub Josef123be7a2016-12-12 16:02:36 +0100517
518Node enforcing from client using SSH launcher
519
520.. code-block:: yaml
521
522 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100523 client:
524 node:
525 node01:
526 remote_home: /remote/home/path
527 desc: node-description
528 num_executors: 1
529 node_mode: Normal
530 ret_strategy: Always
531 labels:
532 - example
533 - label
534 launcher:
535 type: ssh
536 host: test-launcher
537 port: 22
538 username: launcher-user
539 password: launcher-pass
Jakub Josef123be7a2016-12-12 16:02:36 +0100540
541Setting node labels
542
543.. code-block:: yaml
544
545 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100546 client:
547 label:
548 node-name:
549 lbl_text: label-offline
550 append: false # set true for label append instead of replace
Jakub Josefd8e04292016-11-28 18:02:27 +0100551
Jakub Josef60cc9d22017-01-18 12:02:14 +0100552SMTP server settings from client
553
554.. code-block:: yaml
555
556 jenkins:
557 client:
558 smtp:
559 host: "smtp.domain.com"
560 username: "user@domain.cz"
561 password: "smtp-password"
562 port: 25
563 ssl: false
564 reply_to: reply_to@address.com
565
Jakub Josefa6d4c832017-01-19 14:06:12 +0100566Slack plugin configuration
567
568.. code-block:: yaml
569
570 jenkins:
571 client:
572 slack:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100573 team_domain: example.com
574 token: slack-token
575 room: slack-room
Jakub Josef6e0cda92017-02-14 18:01:58 +0100576 token_credential_id: cred_id
Ales Komarekffe8bb22017-02-09 11:10:16 +0100577 send_as: Some slack user
Jakub Josefa6d4c832017-01-19 14:06:12 +0100578
Jakub Josef6e0cda92017-02-14 18:01:58 +0100579Pipeline global libraries setup
580
581.. code-block:: yaml
582
583 jenkins:
584 client:
585 lib:
586 my-pipeline-library:
587 enabled: true
588 url: https://path-to-my-library
589 credential_id: github
590 branch: master # optional, default master
591 implicit: true # optional default true
Jakub Josefd8e04292016-11-28 18:02:27 +0100592
Ales Komarek4c0bab12016-01-22 12:10:50 +0100593Usage
594=====
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200595
Ales Komarek4c0bab12016-01-22 12:10:50 +0100596Generate password hash:
597
598.. code-block:: bash
599
600 echo -n "salt{plainpassword}" | openssl dgst -sha256
601
602Place in the configuration ``salt:hashpassword``.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200603
Ales Komarekffe8bb22017-02-09 11:10:16 +0100604
605External links
606==============
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200607
608* https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins
Filip Pytlounadf72fa2017-02-02 13:02:03 +0100609
Ales Komarekffe8bb22017-02-09 11:10:16 +0100610
Filip Pytlounadf72fa2017-02-02 13:02:03 +0100611Documentation and Bugs
612======================
613
614To learn how to install and update salt-formulas, consult the documentation
615available online at:
616
617 http://salt-formulas.readthedocs.io/
618
619In the unfortunate event that bugs are discovered, they should be reported to
620the appropriate issue tracker. Use Github issue tracker for specific salt
621formula:
622
623 https://github.com/salt-formulas/salt-formula-jenkins/issues
624
625For feature requests, bug reports or blueprints affecting entire ecosystem,
626use Launchpad salt-formulas project:
627
628 https://launchpad.net/salt-formulas
629
630You can also join salt-formulas-users team and subscribe to mailing list:
631
632 https://launchpad.net/~salt-formulas-users
633
634Developers wishing to work on the salt-formulas projects should always base
635their work on master branch and submit pull request against specific formula.
636
637 https://github.com/salt-formulas/salt-formula-jenkins
638
639Any questions or feedback is always welcome so feel free to join our IRC
640channel:
641
642 #salt-formulas @ irc.freenode.net