Refactor packer ci templates
[releng/global-jjb.git] / jjb / lf-ci-jobs.yaml
1 ---
2 - job-group:
3     name: '{project-name}-ci-jobs'
4
5     # This job group contains all the recommended jobs that should be deployed
6     # for any project ci.
7
8     jjb-version: 1.6.2
9
10     jobs:
11       - gerrit-jjb-merge
12       - gerrit-jjb-verify
13
14 - job-group:
15     name: '{project-name}-github-ci-jobs'
16
17     # This job group contains all the recommended jobs that should be deployed
18     # for any project ci that is using github.
19
20     jjb-version: 1.6.2
21
22     jobs:
23       - github-jjb-merge
24       - github-jjb-verify
25
26
27 - job-group:
28     name: '{project-name}-packer-jobs'
29
30     # This job group contains all the recommended jobs that should be deployed
31     # for any project ci that is using packer.
32
33     packer-version: 1.0.2
34
35     jobs:
36       - gerrit-packer-merge
37       - gerrit-packer-verify
38
39
40 - job-group:
41     name: '{project-name}-github-packer-jobs'
42
43     # This job group contains all the recommended jobs that should be deployed
44     # for any project ci that is using packer.
45
46     packer-version: 1.0.2
47
48     jobs:
49       - github-packer-merge
50       - github-packer-verify
51
52 ####################
53 # COMMON FUNCTIONS #
54 ####################
55
56 - builder:
57     name: lf-infra-jjbini
58     builders:
59       - config-file-provider:
60           files:
61             - file-id: jjbini
62               target: '$HOME/.config/jenkins_jobs/jenkins_jobs.ini'
63
64 - lf_packer_file_paths: &lf_packer_file_paths
65     name: lf-packer-file-paths
66     file-paths:
67       # Common files for all projects
68       - compare-type: ANT
69         pattern: 'packer/vars/{platforms}.json'
70       - compare-type: ANT
71         pattern: 'packer/templates/{templates}.json'
72       - compare-type: ANT
73         pattern: 'packer/provision/{templates}.sh'
74       - compare-type: ANT
75         pattern: 'packer/provision/lib/**'
76
77 - lf_packer: &lf_packer_common
78     name: lf-packer-common
79     # Provide configuration common in packer jobs.
80
81     ######################
82     # Default parameters #
83     ######################
84
85     branch: master
86     build-timeout: 45
87     stream: master
88     submodule-recursive: true
89     packer-cloud-settings: packer-cloud-env
90
91     #####################
92     # Job Configuration #
93     #####################
94
95     project-type: freestyle
96     node: '{build-node}'
97
98     properties:
99       - lf-infra-properties:
100           project: '{project}'
101           build-days-to-keep: 7
102
103     parameters:
104       - lf-infra-parameters:
105           project: '{project}'
106           stream: '{stream}'
107           branch: '{branch}'
108       - lf-infra-packer-parameters:
109           packer-version: '{packer-version}'
110
111     wrappers:
112       - lf-infra-wrappers:
113           build-timeout: '{build-timeout}'
114           jenkins-ssh-credential: '{jenkins-ssh-credential}'
115
116     publishers:
117       - lf-infra-publish
118
119 - parameter:
120     name: lf-infra-jjb-parameters
121     parameters:
122       - string:
123           name: JJB_VERSION
124           default: '{jjb-version}'
125           description: Jenkins Job Builder version to download and install.
126
127 - parameter:
128     name: lf-infra-packer-parameters
129     parameters:
130       - string:
131           name: PACKER_VERSION
132           default: '{packer-version}'
133           description: Packer version to download and install.
134
135 - lf_jjb_common: &lf_jjb_common
136     name: lf-jjb-common
137
138     ######################
139     # Default parameters #
140     ######################
141
142     branch: master
143     build-timeout: 10
144     stream: master
145     submodule-recursive: true
146
147     gerrit_trigger_file_paths:
148       - compare-type: ANT
149         pattern: '**/*.sh'
150       - compare-type: ANT
151         pattern: '**/*.yaml'
152
153     #####################
154     # Job Configuration #
155     #####################
156
157     project-type: freestyle
158     node: '{build-node}'
159
160     properties:
161       - lf-infra-properties:
162           project: '{project}'
163           build-days-to-keep: 7
164
165     parameters:
166       - lf-infra-parameters:
167           project: '{project}'
168           stream: '{stream}'
169           branch: '{branch}'
170       - lf-infra-jjb-parameters:
171           jjb-version: '{jjb-version}'
172
173     wrappers:
174       - lf-infra-wrappers:
175           build-timeout: '{build-timeout}'
176           jenkins-ssh-credential: '{jenkins-ssh-credential}'
177
178     publishers:
179       - lf-infra-publish
180
181 #############
182 # JJB Merge #
183 #############
184
185 - lf_jjb_merge: &lf_jjb_merge
186     name: lf-jjb-merge
187
188     # JJB Merge job runs `jenkins-jobs update` to update production job configuration
189     #
190     # Required parameters:
191     #
192     #     :build-node: The node to run build on.
193     #     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
194     #         be configured in defaults.yaml)
195     #     :mvn-settings: The name of settings file containing credentials for
196     #         the project.
197     #
198     # Optional parameters:
199     #
200     #     :branch: Git branch to fetch for the build. (default: master)
201     #     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
202     #     :build-timeout: Timeout in seconds before aborting build. (default: 10)
203     #     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
204     #     :stream: Keyword that can be used to represent a release code-name.
205     #         Often the same as the branch. (default: master)
206     #     :submodule-recursive: Whether to checkout submodules recursively.
207     #         (default: true)
208     #
209     #     :gerrit_merge_triggers: Override Gerrit Triggers.
210     #     :gerrit_trigger_file_paths: Override file paths which can be used to
211     #         filter which file modifications will trigger a build.
212     #         (default defined by lf_jjb_common)
213
214     ######################
215     # Default parameters #
216     ######################
217
218     gerrit_merge_triggers:
219       - change-merged-event
220       - comment-added-contains-event:
221           comment-contains-value: remerge$
222
223     #####################
224     # Job Configuration #
225     #####################
226
227     builders:
228       - lf-infra-jjbini
229       - shell: !include-raw-escape:
230           - ../shell/jjb-install.sh
231           - ../shell/jjb-merge-job.sh
232
233 - job-template:
234     name: '{project-name}-jjb-merge'
235     id: gerrit-jjb-merge
236     <<: *lf_jjb_common
237     # yamllint disable-line rule:key-duplicates
238     <<: *lf_jjb_merge
239
240     git-url: '$GIT_URL/$GERRIT_PROJECT'
241
242     scm:
243       - lf-infra-gerrit-scm:
244           git-url: '{git-url}'
245           refspec: ''
246           branch: '{branch}'
247           submodule-recursive: '{submodule-recursive}'
248           choosing-strategy: default
249           jenkins-ssh-credential: '{jenkins-ssh-credential}'
250
251     triggers:
252       - gerrit:
253           server-name: '{gerrit-server-name}'
254           trigger-on: '{obj:gerrit_merge_triggers}'
255           projects:
256             - project-compare-type: ANT
257               project-pattern: '{project}'
258               branches:
259                 - branch-compare-type: ANT
260                   branch-pattern: '**/{branch}'
261               file-paths: '{obj:gerrit_trigger_file_paths}'
262
263 - job-template:
264     name: '{project-name}-jjb-merge'
265     id: github-jjb-merge
266     <<: *lf_jjb_common
267     # yamllint disable-line rule:key-duplicates
268     <<: *lf_jjb_merge
269
270     properties:
271       - github:
272           url: '{git-url}/{github-org}/{project}'
273
274     scm:
275       - lf-infra-github-scm:
276           url: '{git-clone-url}{github-org}/{project}'
277           refspec: ''
278           branch: '{branch}'
279           submodule-recursive: '{submodule-recursive}'
280           choosing-strategy: default
281           jenkins-ssh-credential: '{jenkins-ssh-credential}'
282
283     triggers:
284       - github
285       - pollscm:
286           cron: ''
287       - lf-infra-github-pr-trigger:
288           trigger-phrase: '^remerge$'
289           only-trigger-phrase: true
290           status-context: 'JJB Merge'
291           permit-all: false
292           github-hooks: true
293           github-org: '{github-org}'
294           github_pr_whitelist: '{obj:github_pr_whitelist}'
295           github_pr_admin_list: '{obj:github_pr_admin_list}'
296
297 ##############
298 # JJB Verify #
299 ##############
300
301 - lf_jjb_verify: &lf_jjb_verify
302     name: lf-jjb-verify
303
304     # JJB Verify job runs `jenkins-jobs test` to validate JJB syntax
305     #
306     # Required parameters:
307     #
308     #     :build-node: The node to run build on.
309     #     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
310     #         be configured in defaults.yaml)
311     #     :mvn-settings: The name of settings file containing credentials for
312     #         the project.
313     #
314     # Optional parameters:
315     #
316     #     :branch: Git branch to fetch for the build. (default: master)
317     #     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
318     #     :build-timeout: Timeout in seconds before aborting build. (default: 10)
319     #     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
320     #     :stream: Keyword that can be used to represent a release code-name.
321     #         Often the same as the branch. (default: master)
322     #     :submodule-recursive: Whether to checkout submodules recursively.
323     #         (default: true)
324     #
325     #     :gerrit_verify_triggers: Override Gerrit Triggers.
326     #     :gerrit_trigger_file_paths: Override file paths which can be used to
327     #         filter which file modifications will trigger a build.
328     #         (default defined by lf_jjb_common)
329
330     ######################
331     # Default parameters #
332     ######################
333
334     gerrit_verify_triggers:
335       - patchset-created-event:
336           exclude-drafts: false
337           exclude-trivial-rebase: false
338           exclude-no-code-change: false
339       - draft-published-event
340       - comment-added-contains-event:
341           comment-contains-value: recheck$
342
343     #####################
344     # Job Configuration #
345     #####################
346
347     concurrent: true
348
349     builders:
350       - lf-infra-jjbini
351       - shell: !include-raw-escape:
352           - ../shell/git-validate-jira-urls.sh
353           - ../shell/jjb-install.sh
354           - ../shell/jjb-verify-job.sh
355           - ../shell/jjb-check-unicode.sh
356       - lf-infra-gpg-verify-git-signature
357
358 - job-template:
359     name: '{project-name}-jjb-verify'
360     id: gerrit-jjb-verify
361     <<: *lf_jjb_common
362     # yamllint disable-line rule:key-duplicates
363     <<: *lf_jjb_verify
364
365     git-url: '$GIT_URL/$GERRIT_PROJECT'
366
367     scm:
368       - lf-infra-gerrit-scm:
369           git-url: '{git-url}'
370           refspec: '$GERRIT_REFSPEC'
371           branch: '$GERRIT_BRANCH'
372           submodule-recursive: '{submodule-recursive}'
373           choosing-strategy: gerrit
374           jenkins-ssh-credential: '{jenkins-ssh-credential}'
375
376     triggers:
377       - gerrit:
378           server-name: '{gerrit-server-name}'
379           trigger-on: '{obj:gerrit_verify_triggers}'
380           projects:
381             - project-compare-type: ANT
382               project-pattern: '{project}'
383               branches:
384                 - branch-compare-type: ANT
385                   branch-pattern: '**/{branch}'
386               file-paths: '{obj:gerrit_trigger_file_paths}'
387
388 - job-template:
389     name: '{project-name}-jjb-verify'
390     id: github-jjb-verify
391     <<: *lf_jjb_common
392     # yamllint disable-line rule:key-duplicates
393     <<: *lf_jjb_verify
394
395     properties:
396       - github:
397           url: '{git-url}/{github-org}/{project}'
398
399     scm:
400       - lf-infra-github-scm:
401           url: '{git-clone-url}{github-org}/{project}'
402           refspec: '+refs/pull/*:refs/remotes/origin/pr/*'
403           branch: '{branch}'
404           submodule-recursive: '{submodule-recursive}'
405           choosing-strategy: default
406           jenkins-ssh-credential: '{jenkins-ssh-credential}'
407
408     triggers:
409       - lf-infra-github-pr-trigger:
410           trigger-phrase: '^recheck$'
411           only-trigger-phrase: false
412           status-context: 'JJB Verify'
413           permit-all: true
414           github-hooks: true
415           github-org: ''
416           github_pr_whitelist:
417             - ''
418           github_pr_admin_list:
419             - ''
420
421 ################
422 # Packer Merge #
423 ################
424
425 - lf_packer_merge: &lf_packer_merge
426     name: lf-packer-merge
427
428     # Packer Merge job runs `packer build` to build system images in the cloud.
429     #
430     # Required parameters:
431     #
432     #     :build-node: The node to run build on.
433     #     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
434     #         be configured in defaults.yaml)
435     #     :mvn-settings: The name of settings file containing credentials for
436     #         the project.
437     #     :platforms: Platform or distribution to build. Typically json file
438     #         found in the packer/vars directory. (Example: centos)
439     #     :template: System template to build. Typically shell script found in
440     #         the packer/provision directory. (Example: java-builder)
441     #
442     # Optional parameters:
443     #
444     #     :branch: Git branch to fetch for the build. (default: master)
445     #     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
446     #     :build-timeout: Timeout in seconds before aborting build. (default: 10)
447     #     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
448     #     :packer-cloud-settings: Name of settings file containing credentials
449     #         for the cloud that packer will build on. (default: packer-cloud-env)
450     #     :packer-version: Version of packer to install / use in build. (default: 1.0.2)
451     #     :stream: Keyword that can be used to represent a release code-name.
452     #         Often the same as the branch. (default: master)
453     #     :submodule-recursive: Whether to checkout submodules recursively.
454     #         (default: true)
455     #
456     #     :gerrit_verify_triggers: Override Gerrit Triggers.
457     #     :gerrit_trigger_file_paths: Override file paths which can be used to
458     #         filter which file modifications will trigger a build.
459     #         (default defined by lf_jjb_common)
460
461     ######################
462     # Default parameters #
463     ######################
464
465     gerrit_merge_triggers:
466       - change-merged-event
467       - comment-added-contains-event:
468           comment-contains-value: remerge$
469
470     #####################
471     # Job Configuration #
472     #####################
473
474     builders:
475       - lf-infra-packer-validate:
476           packer-cloud-settings: '{packer-cloud-settings}'
477           packer-version: '{packer-version}'
478       - lf-infra-packer-build:
479           packer-cloud-settings: '{packer-cloud-settings}'
480           packer-version: '{packer-version}'
481           platform: '{platforms}'
482           template: '{templates}'
483
484 - job-template:
485     name: '{project-name}-packer-merge-{platforms}-{templates}'
486     id: gerrit-packer-merge
487     <<: *lf_packer_common
488     # yamllint disable-line rule:key-duplicates
489     <<: *lf_packer_merge
490
491     git-url: '$GIT_URL/$GERRIT_PROJECT'
492
493     scm:
494       - lf-infra-gerrit-scm:
495           git-url: '{git-url}'
496           refspec: '$GERRIT_REFSPEC'
497           branch: '$GERRIT_BRANCH'
498           submodule-recursive: '{submodule-recursive}'
499           choosing-strategy: gerrit
500           jenkins-ssh-credential: '{jenkins-ssh-credential}'
501
502     triggers:
503       - timed: '00 10 1 * *'
504       - gerrit:
505           server-name: '{gerrit-server-name}'
506           trigger-on: '{obj:gerrit_merge_triggers}'
507           projects:
508             - project-compare-type: ANT
509               project-pattern: '{project}'
510               branches:
511                 - branch-compare-type: ANT
512                   branch-pattern: '**/{branch}'
513               <<: *lf_packer_file_paths
514
515 - job-template:
516     name: '{project-name}-packer-merge-{platforms}-{templates}'
517     id: github-packer-merge
518     <<: *lf_packer_common
519     # yamllint disable-line rule:key-duplicates
520     <<: *lf_packer_merge
521
522     properties:
523       - github:
524           url: '{git-url}/{github-org}/{project}'
525
526     scm:
527       - lf-infra-github-scm:
528           url: '{git-clone-url}{github-org}/{project}'
529           refspec: ''
530           branch: '{branch}'
531           submodule-recursive: '{submodule-recursive}'
532           choosing-strategy: default
533           jenkins-ssh-credential: '{jenkins-ssh-credential}'
534
535     triggers:
536       - timed: '00 10 1 * *'
537       - github
538       - pollscm:
539           cron: ''
540       - lf-infra-github-pr-trigger:
541           trigger-phrase: '^remerge$'
542           only-trigger-phrase: true
543           status-context: 'Packer {platforms}-${templates} Merge'
544           permit-all: false
545           github-hooks: true
546           github-org: '{github-org}'
547           github_pr_whitelist: '{obj:github_pr_whitelist}'
548           github_pr_admin_list: '{obj:github_pr_admin_list}'
549
550 #################
551 # Packer Verify #
552 #################
553
554 - lf_packer_verify: &lf_packer_verify
555     name: lf-packer-verify
556
557     # Packer Verify job runs `packer validate` to verify packer configuration.
558     #
559     # Required parameters:
560     #
561     #     :build-node: The node to run build on.
562     #     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
563     #         be configured in defaults.yaml)
564     #     :mvn-settings: The name of settings file containing credentials for
565     #         the project.
566     #
567     # Optional parameters:
568     #
569     #     :branch: Git branch to fetch for the build. (default: master)
570     #     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
571     #     :build-timeout: Timeout in seconds before aborting build. (default: 10)
572     #     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
573     #     :packer-cloud-settings: Name of settings file containing credentials
574     #         for the cloud that packer will build on. (default: packer-cloud-env)
575     #     :packer-version: Version of packer to install / use in build. (default: 1.0.2)
576     #     :stream: Keyword that can be used to represent a release code-name.
577     #         Often the same as the branch. (default: master)
578     #     :submodule-recursive: Whether to checkout submodules recursively.
579     #         (default: true)
580     #
581     #     :gerrit_verify_triggers: Override Gerrit Triggers.
582     #     :gerrit_trigger_file_paths: Override file paths which can be used to
583     #         filter which file modifications will trigger a build.
584     #         (default defined by lf_jjb_common)
585
586     ######################
587     # Default parameters #
588     ######################
589
590     build-timeout: 10
591
592     gerrit_verify_triggers:
593       - patchset-created-event:
594           exclude-drafts: false
595           exclude-trivial-rebase: false
596           exclude-no-code-change: false
597       - draft-published-event
598       - comment-added-contains-event:
599           comment-contains-value: recheck$
600
601     #####################
602     # Job Configuration #
603     #####################
604
605     concurrent: true
606
607     builders:
608       - lf-infra-packer-validate:
609           packer-cloud-settings: '{packer-cloud-settings}'
610           packer-version: '{packer-version}'
611
612 - job-template:
613     name: '{project-name}-packer-verify'
614     id: gerrit-packer-verify
615     <<: *lf_packer_common
616     # yamllint disable-line rule:key-duplicates
617     <<: *lf_packer_verify
618
619     git-url: '$GIT_URL/$GERRIT_PROJECT'
620
621     scm:
622       - lf-infra-gerrit-scm:
623           git-url: '{git-url}'
624           refspec: '$GERRIT_REFSPEC'
625           branch: '$GERRIT_BRANCH'
626           submodule-recursive: '{submodule-recursive}'
627           choosing-strategy: gerrit
628           jenkins-ssh-credential: '{jenkins-ssh-credential}'
629
630     triggers:
631       - gerrit:
632           server-name: '{gerrit-server-name}'
633           trigger-on: '{obj:gerrit_verify_triggers}'
634           projects:
635             - project-compare-type: ANT
636               project-pattern: '{project}'
637               branches:
638                 - branch-compare-type: ANT
639                   branch-pattern: '**/{branch}'
640               <<: *lf_packer_file_paths
641
642 - job-template:
643     name: '{project-name}-packer-verify'
644     id: github-packer-verify
645     <<: *lf_packer_common
646     # yamllint disable-line rule:key-duplicates
647     <<: *lf_packer_verify
648
649     properties:
650       - github:
651           url: '{git-url}/{github-org}/{project}'
652
653     scm:
654       - lf-infra-github-scm:
655           url: '{git-clone-url}{github-org}/{project}'
656           refspec: '+refs/pull/*:refs/remotes/origin/pr/*'
657           branch: '{branch}'
658           submodule-recursive: '{submodule-recursive}'
659           choosing-strategy: default
660           jenkins-ssh-credential: '{jenkins-ssh-credential}'
661
662     triggers:
663       - lf-infra-github-pr-trigger:
664           trigger-phrase: '^recheck$'
665           only-trigger-phrase: false
666           status-context: 'Packer Verify'
667           permit-all: true
668           github-hooks: true
669           github-org: ''
670           github_pr_whitelist:
671             - ''
672           github_pr_admin_list:
673             - ''