blob: e45c4b8b2c711b668e1196c0b5804861d703c610 [file] [log] [blame]
Ales Komarekffe8bb22017-02-09 11:10:16 +01001===============
2Jenkins formula
3===============
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +02004
Dan Alvizu5d9336b2018-01-15 14:43:51 -07005Jenkins CI is an open source automation server written in Java. Jenkins
6helps to automate the non-human part of software development process, with
7continuous integration and facilitating technical aspects of continuous delivery.
8
9(*Source*: `Wikipedia <https://en.wikipedia.org/wiki/Jenkins_(software)>`_ )
10
11More information can be found at `<https://jenkins.io/>`_
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020012
Ales Komarekffe8bb22017-02-09 11:10:16 +010013Setup jenkins client, works with Salt 2016.3+, supports pipeline workflow
14projects only now.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020015
Dan Alvizu5d9336b2018-01-15 14:43:51 -070016Dependencies
17==============
18
19To install on Ubuntu, you will need to add the jenkins debian repository to the target
20server. You can do this with the `salt-formula-linux formula <https://github.com/salt-formulas/salt-formula-linux>`_ ,
21with the following pillar data:
22
23.. code-block:: yaml
24
25 linux:
26 system:
27 enabled: true
28 repo:
29 jenkins:
30 enabled: true
31 source: "deb http://pkg.jenkins.io/debian-stable binary/"
32 key_url: "https://pkg.jenkins.io/debian/jenkins-ci.org.key"
33
34This state will need to be applied *before* the jenkins state.
35
36Using this formula
37==================
38
39To use this formula, you must install the formula to your salt master as documented
40in `saltstack formula docs <https://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html#installation>`_
41
42This formula is driven by pillar data, and can be used to install either a Jenkins Master
43or Client. See pillar data below for examples.
44
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020045
Ales Komareke5a1ed62016-08-27 12:02:48 +020046Sample pillars
47==============
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020048
Ales Komarekffe8bb22017-02-09 11:10:16 +010049Master role
50-----------
Ales Komareke5a1ed62016-08-27 12:02:48 +020051
52Simple master with reverse proxy
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020053
54.. code-block:: yaml
55
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020056 nginx:
57 server:
58 site:
59 jenkins:
60 enabled: true
61 type: nginx_proxy
62 name: jenkins
63 proxy:
64 host: 127.0.0.1
65 port: 8080
66 protocol: http
67 host:
68 name: jenkins.example.com
69 port: 80
70 jenkins:
71 master:
72 mode: EXCLUSIVE
Filip Pytloun52b9c2c2016-01-28 13:45:57 +010073 # Do not manage config.xml from Salt, use UI instead
74 no_config: true
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +020075 slaves:
76 - name: slave01
77 label: pbuilder
78 executors: 2
79 - name: slave02
80 label: image_builder
81 mode: EXCLUSIVE
82 executors: 2
83 views:
84 - name: "Package builds"
85 regex: "debian-build-.*"
86 - name: "Contrail builds"
87 regex: "contrail-build-.*"
88 - name: "Aptly"
89 regex: "aptly-.*"
90 plugins:
91 - name: slack
92 - name: extended-choice-parameter
93 - name: rebuild
94 - name: test-stability
95
Ales Komarekffe8bb22017-02-09 11:10:16 +010096Jenkins master with experimental plugin source support
Ales Komarekaf967ee2016-08-31 19:38:50 +020097
98.. code-block:: yaml
99
100 jenkins:
101 master:
102 enabled: true
103 update_site_url: 'http://updates.jenkins-ci.org/experimental/update-center.json'
104
Ales Komarekffe8bb22017-02-09 11:10:16 +0100105SMTP server settings
Ales Komarekaf967ee2016-08-31 19:38:50 +0200106
Ales Komarekffe8bb22017-02-09 11:10:16 +0100107.. code-block:: yaml
108
109 jenkins:
110 master:
111 email:
112 engine: "smtp"
113 host: "smtp.domain.com"
114 user: "user@domain.cz"
115 password: "smtp-password"
116 port: 25
117
Jakub Josefbf0b73e2017-03-22 14:32:45 +0100118Script approvals from client
119
120.. code-block:: yaml
121
122 jenkins:
123 client:
124 approved_scripts:
125 - method groovy.json.JsonSlurperClassic parseText java.lang.String
126
127
Ales Komarekffe8bb22017-02-09 11:10:16 +0100128Script approvals
129
130.. code-block:: yaml
131
132 jenkins:
133 master:
134 approved_scripts:
135 - method groovy.json.JsonSlurperClassic parseText java.lang.String
136
137User enforcement
138
139.. code-block:: yaml
140
141 jenkins:
142 master:
143 user:
144 admin:
145 api_token: xxxxxxxxxx
146 password: admin_password
147 email: admin@domain.com
148 user01:
149 api_token: xxxxxxxxxx
150 password: user_password
151 email: user01@domain.com
152
153
154Agent (slave) role
155------------------
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200156
157.. code-block:: yaml
158
Ales Komarek4c0bab12016-01-22 12:10:50 +0100159 jenkins:
160 slave:
161 master:
162 host: jenkins.example.com
163 port: 80
Michael Kutý37a35952016-06-10 23:51:36 +0200164 protocol: http
Ales Komarek4c0bab12016-01-22 12:10:50 +0100165 user:
166 name: jenkins_slave
167 password: dexiech6AepohthaiHook2iesh7ol5ook4Ov3leid3yek6daid2ooNg3Ee2oKeYo
168 gpg:
169 keypair_id: A76882D3
170 public_key: |
171 -----BEGIN PGP PUBLIC KEY BLOCK-----
172 ...
173 private_key: |
174 -----BEGIN PGP PRIVATE KEY BLOCK-----
175 ...
Ales Komarekaf967ee2016-08-31 19:38:50 +0200176
Ales Komarekffe8bb22017-02-09 11:10:16 +0100177
178Client role
179-----------
Ales Komareke5a1ed62016-08-27 12:02:48 +0200180
181Simple client with workflow job definition
182
183.. code-block:: yaml
184
185 jenkins:
186 client:
187 master:
188 host: jenkins.example.com
189 port: 80
190 protocol: http
191 job:
192 jobname:
193 type: workflow
194 param:
195 bool_param:
196 type: boolean
197 description: true/false
198 default: true
199 string_param:
200 type: string
201 description: 1 liner
202 default: default_string
203 text_param:
204 type: text
205 description: multi-liner
206 default: default_text
Filip Pytlounebd4d172016-09-01 14:23:20 +0200207 jobname_scm:
208 type: workflow-scm
209 concurrent: false
210 scm:
211 type: git
212 url: https://github.com/jenkinsci/docker.git
213 branch: master
214 script: Jenkinsfile
215 github:
216 url: https://github.com/jenkinsci/docker
217 name: "Jenkins Docker Image"
218 trigger:
Tomáš Kukrála9cf2c62017-03-04 11:25:20 +0100219 timer:
220 spec: "H H * * *"
Filip Pytlounebd4d172016-09-01 14:23:20 +0200221 github:
222 pollscm:
223 spec: "H/15 * * * *"
224 reverse:
225 projects:
226 - test1
227 - test2
228 state: SUCCESS
229 param:
230 bool_param:
231 type: boolean
232 description: true/false
233 default: true
234 string_param:
235 type: string
236 description: 1 liner
237 default: default_string
238 text_param:
239 type: text
240 description: multi-liner
241 default: default_text
Ales Komareke5a1ed62016-08-27 12:02:48 +0200242
Ales Komarekffe8bb22017-02-09 11:10:16 +0100243Inline Groovy scripts
Ales Komareke5a1ed62016-08-27 12:02:48 +0200244
245.. code-block:: yaml
246
247 jenkins:
248 client:
249 job:
250 test_workflow_jenkins_simple:
251 type: workflow
252 display_name: Test jenkins simple workflow
Ales Komarek5b672fd2016-08-29 16:05:03 +0200253 script:
254 content: |
255 node {
256 stage 'Stage 1'
257 echo 'Hello World 1'
258 stage 'Stage 2'
259 echo 'Hello World 2'
260 }
Ales Komareke5a1ed62016-08-27 12:02:48 +0200261 test_workflow_jenkins_input:
262 type: workflow
263 display_name: Test jenkins workflow inputs
Ales Komarek5b672fd2016-08-29 16:05:03 +0200264 script:
265 content: |
266 node {
267 stage 'Enter string'
268 input message: 'Enter job parameters', ok: 'OK', parameters: [
269 string(defaultValue: 'default', description: 'Enter a string.', name: 'string'),
270 ]
271 stage 'Enter boolean'
272 input message: 'Enter job parameters', ok: 'OK', parameters: [
273 booleanParam(defaultValue: false, description: 'Select boolean.', name: 'Bool'),
274 ]
275 stage 'Enter text'
276 input message: 'Enter job parameters', ok: 'OK', parameters: [
277 text(defaultValue: '', description: 'Enter multiline', name: 'Multiline')
278 ]
279 }
Ales Komareke5a1ed62016-08-27 12:02:48 +0200280
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200281
Ales Komarekffe8bb22017-02-09 11:10:16 +0100282GIT controlled groovy scripts
Ales Komarekdaf31f72016-08-29 11:00:13 +0200283
284.. code-block:: yaml
285
286 jenkins:
287 client:
288 source:
Ales Komarek5b672fd2016-08-29 16:05:03 +0200289 base:
290 engine: git
291 address: repo_url
292 branch: branch
293 domain:
294 engine: git
295 address: domain_url
296 branch: branch
Ales Komarekdaf31f72016-08-29 11:00:13 +0200297 job:
298 test_workflow_jenkins_simple:
299 type: workflow
300 display_name: Test jenkins simple workflow
Ales Komarek5b672fd2016-08-29 16:05:03 +0200301 param:
302 bool_param:
303 type: boolean
304 description: true/false
305 default: true
306 script:
307 repository: base
308 file: workflows/test_workflow_jenkins_simple.groovy
Ales Komarekdaf31f72016-08-29 11:00:13 +0200309 test_workflow_jenkins_input:
310 type: workflow
311 display_name: Test jenkins workflow inputs
Ales Komarek5b672fd2016-08-29 16:05:03 +0200312 script:
313 repository: domain
314 file: workflows/test_workflow_jenkins_input.groovy
315 test_workflow_jenkins_input_jenkinsfile:
316 type: workflow
317 display_name: Test jenkins workflow inputs (jenknisfile)
318 script:
319 repository: domain
320 file: workflows/test_workflow_jenkins_input/Jenkinsfile
Ales Komarekdaf31f72016-08-29 11:00:13 +0200321
Ales Komarek5b672fd2016-08-29 16:05:03 +0200322GIT controlled groovy script with shared libraries
323
324.. code-block:: yaml
325
326 jenkins:
327 client:
328 source:
329 base:
330 engine: git
331 address: repo_url
332 branch: branch
333 domain:
334 engine: git
335 address: domain_url
336 branch: branch
337 job:
338 test_workflow_jenkins_simple:
339 type: workflow
340 display_name: Test jenkins simple workflow
341 param:
342 bool_param:
343 type: boolean
344 description: true/false
345 default: true
346 script:
347 repository: base
348 file: workflows/test_workflow_jenkins_simple.groovy
349 libs:
350 - repository: base
351 file: macros/cookiecutter.groovy
352 - repository: base
353 file: macros/git.groovy
Ales Komarekdaf31f72016-08-29 11:00:13 +0200354
Jakub Josef120714d2017-02-09 16:29:18 +0100355Setting job max builds to keep (amount of last builds stored on Jenkins master)
356
357.. code-block:: yaml
358
359 jenkins:
360 client:
361 job:
362 my-amazing-job:
363 type: workflow
364 discard:
365 build:
366 keep_num: 5
367 keep_days: 5
368 artifact:
369 keep_num: 6
370 keep_days: 6
371
Ales Komarekffe8bb22017-02-09 11:10:16 +0100372
373Using job templates in similar way as in jjb. For now just 1 defined param is
374supported.
375
376.. code-block:: yaml
377
378 jenkins:
379 client:
380 job_template:
381 test_workflow_template:
382 name: test-{{formula}}-workflow
383 template:
384 type: workflow
385 display_name: Test jenkins {{name}} workflow
386 param:
387 repo_param:
388 type: string
389 default: repo/{{formula}}
390 script:
391 repository: base
392 file: workflows/test_formula_workflow.groovy
393 param:
394 formula:
395 - aodh
396 - linux
397 - openssh
398
399Interpolating parameters for job templates.
400
Filip Pytloun83129fc2017-02-23 10:07:32 +0100401.. code-block:: yaml
402
Ales Komarekffe8bb22017-02-09 11:10:16 +0100403 _param:
404 salt_formulas:
405 - aodh
406 - git
407 - nova
408 - xorg
409 jenkins:
410 client:
411 job_template:
412 test_workflow_template:
413 name: test-{{formula}}-workflow
414 template:
415 ...
416 param:
417 formula: ${_param:salt_formulas}
418
Filip Pytloun83129fc2017-02-23 10:07:32 +0100419Or simply define multiple jobs and it's parameters to replace from template:
420
421.. code-block:: yaml
422
423 jenkins:
424 client:
425 job_template:
426 test_workflow_template:
427 name: test-{{name}}-{{myparam}}
428 template:
429 ...
430 jobs:
431 - name: firstjob
432 myparam: dummy
433 - name: secondjob
434 myparam: dummyaswell
Ales Komarekffe8bb22017-02-09 11:10:16 +0100435
Jakub Josef2a7739b2017-01-24 18:33:44 +0100436Purging undefined jobs from Jenkins
437
438.. code-block:: yaml
439
440 jenkins:
441 client:
442 purge_jobs: true
Ales Komarekffe8bb22017-02-09 11:10:16 +0100443 job:
444 my-amazing-job:
445 type: workflow
Jakub Josef2a7739b2017-01-24 18:33:44 +0100446
Jakub Josef10b4e102017-01-05 18:18:41 +0100447Plugins management from client
448
449.. code-block:: yaml
450
451
452 jenkins:
453 client:
454 plugin:
455 swarm:
456 restart: false
457 hipchat:
458 enabled: false
459 restart: true
460
Jakub Josef063a7532017-01-11 15:48:01 +0100461LDAP configuration (depends on LDAP plugin)
462
463.. code-block:: yaml
464
465 jenkins:
466 client:
467 security:
468 ldap:
469 server: 1.2.3.4
470 root_dn: dc=foo,dc=com
471 user_search_base: cn=users,cn=accounts
472 manager_dn: ""
473 manager_password: password
474 user_search: ""
475 group_search_base: ""
476 inhibit_infer_root_dn: false
477
478
479Matrix configuration (depends on auth-matrix plugin)
480
481.. code-block:: yaml
482
483 jenkins:
484 client:
485 security:
486 matrix:
Jakub Josef0ee470e2017-01-17 11:46:58 +0100487 # set true for use ProjectMatrixAuthStrategy instead of GlobalMatrixAuthStrategy
488 project_based: false
Jakub Josef063a7532017-01-11 15:48:01 +0100489 permissions:
490 Jenkins:
491 # administrator access
492 ADMINISTER:
493 - admin
494 # read access (anonymous too)
495 READ:
496 - anonymous
497 - user1
498 - user2
499 # agents permissions
500 MasterComputer:
501 BUILD:
502 - user3
503 # jobs permissions
504 hudson:
505 model:
506 Item:
507 BUILD:
508 - user4
509
510`Common matrix strategies <https://github.com/arbabnazar/configuration/blob/c08a5eaf4e04a68d2481375502a926517097b253/playbooks/roles/tools_jenkins/templates/projectBasedMatrixSecurity.groovy.j2>`_
511
Jakub Josef7bb17ab2017-01-12 14:52:53 +0100512Views enforcing from client
513
514.. code-block:: yaml
515
516 jenkins:
517 client:
518 view:
519 my-list-view:
520 enabled: true
521 type: ListView
Jakub Josef7d9fce32017-03-24 16:46:56 +0100522 include_regex: ".*"
Jakub Josef7bb17ab2017-01-12 14:52:53 +0100523 my-view:
524 # set false to disable
525 enabled: true
526 type: MyView
527
528View specific params:
529
Jakub Josef7d9fce32017-03-24 16:46:56 +0100530- include_regex for ListView and CategorizedJobsView
531- categories for CategorizedJobsView
532
533Categorized views
534
535.. code-block:: yaml
536
537 jenkins:
538 client:
539 view:
540 my-categorized-view:
541 enabled: true
542 type: CategorizedJobsView
543 include_regex: ".*"
544 categories:
545 - group_regex: "aptly-.*-nightly-testing"
546 naming_rule: "Nightly -> Testing"
547 - group_regex: "aptly-.*-nightly-production"
548 naming_rule: "Nightly -> Production"
Jakub Josef7bb17ab2017-01-12 14:52:53 +0100549
Jakub Josef063a7532017-01-11 15:48:01 +0100550
Jakub Josef123be7a2016-12-12 16:02:36 +0100551Credentials enforcing from client
552
553.. code-block:: yaml
554
555 jenkins:
556 client:
557 credential:
558 cred_first:
559 username: admin
560 password: password
561 cred_second:
562 username: salt
563 password: password
564 cred_with_key:
565 username: admin
566 key: SOMESSHKEY
567
568Users enforcing from client
569
570.. code-block:: yaml
571
572 jenkins:
573 client:
574 user:
575 admin:
576 password: admin_password
577 admin: true
578 user01:
579 password: user_password
580
581Node enforcing from client using JNLP launcher
582
583.. code-block:: yaml
584
585 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100586 client:
587 node:
588 node01:
589 remote_home: /remote/home/path
590 desc: node-description
591 num_executors: 1
592 node_mode: Normal
593 ret_strategy: Always
594 labels:
595 - example
596 - label
597 launcher:
598 type: jnlp
Jakub Josef123be7a2016-12-12 16:02:36 +0100599
600Node enforcing from client using SSH launcher
601
602.. code-block:: yaml
603
604 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100605 client:
606 node:
607 node01:
608 remote_home: /remote/home/path
609 desc: node-description
610 num_executors: 1
611 node_mode: Normal
612 ret_strategy: Always
613 labels:
614 - example
615 - label
616 launcher:
617 type: ssh
618 host: test-launcher
619 port: 22
620 username: launcher-user
621 password: launcher-pass
Jakub Josef123be7a2016-12-12 16:02:36 +0100622
Jakub Josef1bb7f442017-05-26 17:02:56 +0200623Configure Jenkins master
624
625.. code-block:: yaml
626
627 jenkins:
628 client:
629 node:
630 master:
631 num_executors: 1
632 node_mode: Normal # or Exclusive
633 labels:
634 - example
635 - label
636
637
Jakub Josef123be7a2016-12-12 16:02:36 +0100638Setting node labels
639
640.. code-block:: yaml
641
642 jenkins:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100643 client:
644 label:
645 node-name:
646 lbl_text: label-offline
647 append: false # set true for label append instead of replace
Jakub Josefd8e04292016-11-28 18:02:27 +0100648
Jakub Josef60cc9d22017-01-18 12:02:14 +0100649SMTP server settings from client
650
651.. code-block:: yaml
652
653 jenkins:
654 client:
655 smtp:
656 host: "smtp.domain.com"
657 username: "user@domain.cz"
658 password: "smtp-password"
659 port: 25
660 ssl: false
661 reply_to: reply_to@address.com
662
Jakub Josefdfb288c2017-04-27 17:29:00 +0200663Jenkins admin user email enforcement from client
664
665.. code-block:: yaml
666
667 jenkins:
668 client:
669 smtp:
670 admin_email: "My Jenkins <jenkins@myserver.com>"
671
672
Jakub Josefa6d4c832017-01-19 14:06:12 +0100673Slack plugin configuration
674
675.. code-block:: yaml
676
677 jenkins:
678 client:
679 slack:
Ales Komarekffe8bb22017-02-09 11:10:16 +0100680 team_domain: example.com
681 token: slack-token
682 room: slack-room
Jakub Josef6e0cda92017-02-14 18:01:58 +0100683 token_credential_id: cred_id
Ales Komarekffe8bb22017-02-09 11:10:16 +0100684 send_as: Some slack user
Jakub Josefa6d4c832017-01-19 14:06:12 +0100685
Jakub Josef6e0cda92017-02-14 18:01:58 +0100686Pipeline global libraries setup
687
688.. code-block:: yaml
689
690 jenkins:
691 client:
692 lib:
693 my-pipeline-library:
694 enabled: true
695 url: https://path-to-my-library
696 credential_id: github
697 branch: master # optional, default master
698 implicit: true # optional default true
Jakub Josefd8e04292016-11-28 18:02:27 +0100699
Jakub Josef01940252017-05-10 14:01:22 +0200700Artifactory server enforcing
701
702.. code-block:: yaml
703
704 jenkins:
705 client:
706 artifactory:
707 my-artifactory-server:
708 enabled: true
709 url: https://path-to-my-library
710 credential_id: github
711
Jakub Josef184ee1c2017-11-29 16:03:09 +0100712 Jenkins Global env properties enforcing
713
714 .. code-block:: yaml
715
716 jenkins:
717 client:
718 globalenvprop:
719 OFFLINE_DEPLOYMENT:
720 enabled: true
721 name: "OFFLINE_DEPLOYMENT" # optional, default using dict key
722 value: "true"
723
Ales Komarek4c0bab12016-01-22 12:10:50 +0100724Usage
725=====
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200726
Ales Komarek4c0bab12016-01-22 12:10:50 +0100727Generate password hash:
728
729.. code-block:: bash
730
731 echo -n "salt{plainpassword}" | openssl dgst -sha256
732
733Place in the configuration ``salt:hashpassword``.
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200734
Ales Komarekffe8bb22017-02-09 11:10:16 +0100735
736External links
737==============
Filip Pytloun8bfd2bf2015-10-06 16:28:32 +0200738
739* https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins
Filip Pytlounadf72fa2017-02-02 13:02:03 +0100740
Ales Komarekffe8bb22017-02-09 11:10:16 +0100741
Filip Pytlounadf72fa2017-02-02 13:02:03 +0100742Documentation and Bugs
743======================
744
745To learn how to install and update salt-formulas, consult the documentation
746available online at:
747
748 http://salt-formulas.readthedocs.io/
749
750In the unfortunate event that bugs are discovered, they should be reported to
751the appropriate issue tracker. Use Github issue tracker for specific salt
752formula:
753
754 https://github.com/salt-formulas/salt-formula-jenkins/issues
755
756For feature requests, bug reports or blueprints affecting entire ecosystem,
757use Launchpad salt-formulas project:
758
759 https://launchpad.net/salt-formulas
760
761You can also join salt-formulas-users team and subscribe to mailing list:
762
763 https://launchpad.net/~salt-formulas-users
764
765Developers wishing to work on the salt-formulas projects should always base
766their work on master branch and submit pull request against specific formula.
767
768 https://github.com/salt-formulas/salt-formula-jenkins
769
770Any questions or feedback is always welcome so feel free to join our IRC
771channel:
772
773 #salt-formulas @ irc.freenode.net