Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 1 | ======= |
| 2 | Jenkins |
| 3 | ======= |
| 4 | |
Ales Komarek | 4c0bab1 | 2016-01-22 12:10:50 +0100 | [diff] [blame] | 5 | Jenkins is an application that monitors executions of repeated jobs, such as building a software project or jobs run by cron. |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 6 | |
| 7 | Available states |
| 8 | ================ |
| 9 | |
| 10 | .. contents:: |
| 11 | :local: |
| 12 | |
| 13 | ``jenkins.master`` |
| 14 | ------------------ |
| 15 | |
Ales Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 16 | Setup jenkins master. |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 17 | |
| 18 | ``jenkins.slave`` |
| 19 | ----------------- |
| 20 | |
Ales Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 21 | Setup jenkins slave. |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 22 | |
| 23 | ``jenkins.job_builder`` |
| 24 | ----------------------- |
| 25 | |
Ales Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 26 | Setup jenkins job builder. |
| 27 | |
| 28 | ``jenkins.client`` |
| 29 | ------------------ |
| 30 | |
| 31 | Setup jenkins client, works with Salt 2016.3+, supports pipeline workflow projects only now. |
| 32 | |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 33 | |
| 34 | Available metadata |
| 35 | ================== |
| 36 | |
| 37 | .. contents:: |
| 38 | :local: |
| 39 | |
| 40 | ``metadata.jenkins.master.single`` |
| 41 | ---------------------------------- |
| 42 | |
| 43 | Setup single-node master |
| 44 | |
| 45 | |
| 46 | ``metadata.jenkins.slave.single`` |
| 47 | --------------------------------- |
| 48 | |
| 49 | Setup Jenkins slave |
| 50 | |
Ales Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 51 | Sample pillars |
| 52 | ============== |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 53 | |
Ales Komarek | 4c0bab1 | 2016-01-22 12:10:50 +0100 | [diff] [blame] | 54 | Jenkins master |
Ales Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 55 | -------------- |
| 56 | |
| 57 | Simple master with reverse proxy |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 58 | |
| 59 | .. code-block:: yaml |
| 60 | |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 61 | 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 Pytloun | 52b9c2c | 2016-01-28 13:45:57 +0100 | [diff] [blame] | 78 | # Do not manage config.xml from Salt, use UI instead |
| 79 | no_config: true |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 80 | 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 Komarek | af967ee | 2016-08-31 19:38:50 +0200 | [diff] [blame] | 101 | Jenkins 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 Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 111 | Agent (former slave) |
| 112 | -------------------- |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 113 | |
| 114 | .. code-block:: yaml |
| 115 | |
Ales Komarek | 4c0bab1 | 2016-01-22 12:10:50 +0100 | [diff] [blame] | 116 | jenkins: |
| 117 | slave: |
| 118 | master: |
| 119 | host: jenkins.example.com |
| 120 | port: 80 |
Michael KutĂ˝ | 37a3595 | 2016-06-10 23:51:36 +0200 | [diff] [blame] | 121 | protocol: http |
Ales Komarek | 4c0bab1 | 2016-01-22 12:10:50 +0100 | [diff] [blame] | 122 | 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 Komarek | af967ee | 2016-08-31 19:38:50 +0200 | [diff] [blame] | 133 | |
Ales Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 134 | Client |
| 135 | ------ |
| 136 | |
| 137 | Simple 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 Pytloun | ebd4d17 | 2016-09-01 14:23:20 +0200 | [diff] [blame] | 163 | 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 Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 196 | |
Ales Komarek | daf31f7 | 2016-08-29 11:00:13 +0200 | [diff] [blame] | 197 | Inline Groovy script samples |
Ales Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 198 | |
| 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 Komarek | 5b672fd | 2016-08-29 16:05:03 +0200 | [diff] [blame] | 207 | 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 Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 215 | test_workflow_jenkins_input: |
| 216 | type: workflow |
| 217 | display_name: Test jenkins workflow inputs |
Ales Komarek | 5b672fd | 2016-08-29 16:05:03 +0200 | [diff] [blame] | 218 | 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 Komarek | e5a1ed6 | 2016-08-27 12:02:48 +0200 | [diff] [blame] | 234 | |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 235 | |
Ales Komarek | daf31f7 | 2016-08-29 11:00:13 +0200 | [diff] [blame] | 236 | GIT controlled groovy script samples |
| 237 | |
| 238 | .. code-block:: yaml |
| 239 | |
| 240 | jenkins: |
| 241 | client: |
| 242 | source: |
Ales Komarek | 5b672fd | 2016-08-29 16:05:03 +0200 | [diff] [blame] | 243 | base: |
| 244 | engine: git |
| 245 | address: repo_url |
| 246 | branch: branch |
| 247 | domain: |
| 248 | engine: git |
| 249 | address: domain_url |
| 250 | branch: branch |
Ales Komarek | daf31f7 | 2016-08-29 11:00:13 +0200 | [diff] [blame] | 251 | job: |
| 252 | test_workflow_jenkins_simple: |
| 253 | type: workflow |
| 254 | display_name: Test jenkins simple workflow |
Ales Komarek | 5b672fd | 2016-08-29 16:05:03 +0200 | [diff] [blame] | 255 | 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 Komarek | daf31f7 | 2016-08-29 11:00:13 +0200 | [diff] [blame] | 263 | test_workflow_jenkins_input: |
| 264 | type: workflow |
| 265 | display_name: Test jenkins workflow inputs |
Ales Komarek | 5b672fd | 2016-08-29 16:05:03 +0200 | [diff] [blame] | 266 | 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 Komarek | daf31f7 | 2016-08-29 11:00:13 +0200 | [diff] [blame] | 275 | |
Ales Komarek | 5b672fd | 2016-08-29 16:05:03 +0200 | [diff] [blame] | 276 | GIT 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 Komarek | daf31f7 | 2016-08-29 11:00:13 +0200 | [diff] [blame] | 308 | |
Jakub Josef | 10b4e10 | 2017-01-05 18:18:41 +0100 | [diff] [blame^] | 309 | Plugins management from client |
| 310 | |
| 311 | .. code-block:: yaml |
| 312 | |
| 313 | |
| 314 | jenkins: |
| 315 | client: |
| 316 | plugin: |
| 317 | swarm: |
| 318 | restart: false |
| 319 | hipchat: |
| 320 | enabled: false |
| 321 | restart: true |
| 322 | |
Jakub Josef | 123be7a | 2016-12-12 16:02:36 +0100 | [diff] [blame] | 323 | Credentials enforcing from client |
| 324 | |
| 325 | .. code-block:: yaml |
| 326 | |
| 327 | jenkins: |
| 328 | client: |
| 329 | credential: |
| 330 | cred_first: |
| 331 | username: admin |
| 332 | password: password |
| 333 | cred_second: |
| 334 | username: salt |
| 335 | password: password |
| 336 | cred_with_key: |
| 337 | username: admin |
| 338 | key: SOMESSHKEY |
| 339 | |
| 340 | Users enforcing from client |
| 341 | |
| 342 | .. code-block:: yaml |
| 343 | |
| 344 | jenkins: |
| 345 | client: |
| 346 | user: |
| 347 | admin: |
| 348 | password: admin_password |
| 349 | admin: true |
| 350 | user01: |
| 351 | password: user_password |
| 352 | |
| 353 | Node enforcing from client using JNLP launcher |
| 354 | |
| 355 | .. code-block:: yaml |
| 356 | |
| 357 | jenkins: |
| 358 | client: |
| 359 | node: |
| 360 | node01: |
| 361 | remote_home: /remote/home/path |
| 362 | desc: node-description |
| 363 | num_executors: 1 |
| 364 | node_mode: Normal |
| 365 | ret_strategy: Always |
Jakub Josef | 98123ab | 2016-12-14 14:05:01 +0100 | [diff] [blame] | 366 | labels: |
| 367 | - example |
| 368 | - label |
Jakub Josef | 123be7a | 2016-12-12 16:02:36 +0100 | [diff] [blame] | 369 | launcher: |
| 370 | type: jnlp |
| 371 | |
| 372 | Node enforcing from client using SSH launcher |
| 373 | |
| 374 | .. code-block:: yaml |
| 375 | |
| 376 | jenkins: |
| 377 | client: |
| 378 | node: |
| 379 | node01: |
| 380 | remote_home: /remote/home/path |
| 381 | desc: node-description |
| 382 | num_executors: 1 |
| 383 | node_mode: Normal |
| 384 | ret_strategy: Always |
Jakub Josef | 98123ab | 2016-12-14 14:05:01 +0100 | [diff] [blame] | 385 | labels: |
| 386 | - example |
| 387 | - label |
Jakub Josef | 123be7a | 2016-12-12 16:02:36 +0100 | [diff] [blame] | 388 | launcher: |
| 389 | type: ssh |
| 390 | host: test-launcher |
| 391 | port: 22 |
| 392 | username: launcher-user |
| 393 | password: launcher-pass |
| 394 | |
| 395 | Setting node labels |
| 396 | |
| 397 | .. code-block:: yaml |
| 398 | |
| 399 | jenkins: |
| 400 | client: |
| 401 | label: |
| 402 | node-name: |
| 403 | lbl_text: label-offline |
| 404 | append: false # set true for label append instead of replace |
| 405 | |
Jakub Josef | d8e0429 | 2016-11-28 18:02:27 +0100 | [diff] [blame] | 406 | SMTP server settings |
| 407 | |
| 408 | .. code-block:: yaml |
| 409 | |
| 410 | jenkins: |
| 411 | master: |
| 412 | email: |
| 413 | engine: "smtp" |
| 414 | host: "smtp.domain.com" |
| 415 | user: "user@domain.cz" |
| 416 | password: "smtp-password" |
| 417 | port: 25 |
| 418 | |
| 419 | Jenkins script approvals |
| 420 | |
| 421 | .. code-block:: yaml |
| 422 | |
| 423 | jenkins: |
| 424 | master: |
| 425 | approved_scripts: |
| 426 | - method groovy.json.JsonSlurperClassic parseText java.lang.String |
| 427 | |
Jakub Josef | d8e0429 | 2016-11-28 18:02:27 +0100 | [diff] [blame] | 428 | |
Jakub Josef | 123be7a | 2016-12-12 16:02:36 +0100 | [diff] [blame] | 429 | Users enforcing from master |
Jakub Josef | d8e0429 | 2016-11-28 18:02:27 +0100 | [diff] [blame] | 430 | |
| 431 | .. code-block:: yaml |
| 432 | |
| 433 | jenkins: |
| 434 | user: |
| 435 | admin: |
| 436 | api_token: xxxxxxxxxx |
| 437 | password: admin_password |
| 438 | email: admin@domain.com |
| 439 | user01: |
| 440 | api_token: xxxxxxxxxx |
| 441 | password: user_password |
| 442 | email: user01@domain.com |
| 443 | |
Ales Komarek | 4c0bab1 | 2016-01-22 12:10:50 +0100 | [diff] [blame] | 444 | Usage |
| 445 | ===== |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 446 | |
Ales Komarek | 4c0bab1 | 2016-01-22 12:10:50 +0100 | [diff] [blame] | 447 | Generate password hash: |
| 448 | |
| 449 | .. code-block:: bash |
| 450 | |
| 451 | echo -n "salt{plainpassword}" | openssl dgst -sha256 |
| 452 | |
| 453 | Place in the configuration ``salt:hashpassword``. |
Filip Pytloun | 8bfd2bf | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 454 | |
| 455 | Read more |
| 456 | ========= |
| 457 | |
| 458 | * https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins |