Fix: Add Java update alternatives step
[releng/global-jjb.git] / jjb / lf-python-jobs.yaml
1 ---
2 ##########
3 # Macros #
4 ##########
5
6 - builder:
7     name: lf-infra-nexus-iq-python-cli
8     builders:
9       - inject:
10           properties-content: |
11             NEXUS_IQ_PROJECT_NAME={nexus-iq-project-name}
12             REQUIREMENTS_FILE={requirements-file}
13       - shell: !include-raw-escape: ../shell/nexus-iq-python-cli.sh
14
15 - builder:
16     name: lf-infra-tox-install
17     builders:
18       - inject:
19           properties-content: "PYTHON={python-version}"
20       - shell: !include-raw-escape: ../shell/tox-install.sh
21
22 - builder:
23     name: lf-infra-tox-run
24     builders:
25       - inject:
26           properties-content: "PARALLEL={parallel}"
27       - shell: !include-raw-escape: ../shell/tox-run.sh
28
29 ####################
30 # COMMON FUNCTIONS #
31 ####################
32
33 - _lf_python_common: &lf_python_common
34     name: lf-python-common
35
36     ######################
37     # Default parameters #
38     ######################
39
40     archive-artifacts: >
41       **/*.log
42
43     #####################
44     # Job Configuration #
45     #####################
46
47     project-type: freestyle
48     node: "{build-node}"
49
50     properties:
51       - lf-infra-properties:
52           build-days-to-keep: "{build-days-to-keep}"
53
54     parameters:
55       - lf-infra-parameters:
56           project: "{project}"
57           branch: "{branch}"
58           stream: "{stream}"
59
60     wrappers:
61       - lf-infra-wrappers:
62           build-timeout: "{build-timeout}"
63           jenkins-ssh-credential: "{jenkins-ssh-credential}"
64
65     publishers:
66       - lf-infra-publish
67
68 ####################
69 # Tox Nexus IQ CLM #
70 ####################
71
72 - _lf_tox_nexus_iq_clm: &lf_tox_nexus_iq_clm
73     name: lf-tox-nexus-iq-clm
74
75     ######################
76     # Default parameters #
77     ######################
78
79     branch: master
80     build-days-to-keep: 7
81     build-timeout: 15
82     cron: "@weekly"
83     disable-job: false
84     git-url: "$GIT_URL/$PROJECT"
85     github-url: "https://github.com"
86     java-version: openjdk11 # Scanner is a jar
87     nexus-iq-cli-version: 1.140.0-01
88     nexus-iq-namespace: "" # Recommend a trailing dash when set. Example: odl-
89     nexus-target-build: "**/*"
90     pre-build-script: "# pre-build script goes here"
91     python-version: python3
92     requirements-file: requirements.txt
93     stream: master
94     submodule-recursive: true
95     submodule-timeout: 10
96     submodule-disable: false
97     tox-dir: "."
98     tox-envs: "clm"
99
100     #####################
101     # Job Configuration #
102     #####################
103
104     disabled: "{disable-job}"
105
106     parameters:
107       - lf-infra-parameters:
108           project: "{project}"
109           branch: "{branch}"
110           stream: "{stream}"
111       - lf-infra-tox-parameters:
112           tox-dir: "{tox-dir}"
113           tox-envs: "{tox-envs}"
114       - string:
115           name: ARCHIVE_ARTIFACTS
116           default: "{archive-artifacts}"
117           description: Artifacts to archive to the logs server.
118       - string:
119           name: NEXUS_IQ_CLI_VERSION
120           default: "{nexus-iq-cli-version}"
121           description: Nexus IQ CLI jar to download and run.
122       - string:
123           name: NEXUS_TARGET_BUILD
124           default: "{nexus-target-build}"
125           description: File or dir to scan by Nexus CLI.
126
127     wrappers:
128       - lf-infra-wrappers:
129           build-timeout: "{build-timeout}"
130           jenkins-ssh-credential: "{jenkins-ssh-credential}"
131       - credentials-binding:
132           - username-password-separated:
133               credential-id: nexus-iq-xc-clm
134               username: NEXUS_IQ_USER
135               password: NEXUS_IQ_PASSWORD
136
137     builders:
138       - lf-infra-pre-build
139       - lf-update-java-alternatives:
140           java-version: "{java-version}"
141       - lf-infra-tox-install:
142           python-version: "{python-version}"
143       - shell: "{pre-build-script}"
144       - lf-infra-tox-run:
145           parallel: false
146       - lf-infra-nexus-iq-python-cli:
147           nexus-iq-project-name: "{nexus-iq-namespace}{project-name}"
148           requirements-file: "{requirements-file}"
149
150 - job-template:
151     name: "{project-name}-tox-nexus-iq-clm"
152     id: gerrit-tox-nexus-iq-clm
153     <<: *lf_python_common
154     <<: *lf_tox_nexus_iq_clm
155
156     ######################
157     # Default parameters #
158     ######################
159
160     gerrit_nexus_iq_triggers:
161       - comment-added-contains-event:
162           comment-contains-value: '^Patch Set\s+\d+:\s+run-clm\s*$'
163
164     #####################
165     # Job Configuration #
166     #####################
167
168     scm:
169       - lf-infra-gerrit-scm:
170           jenkins-ssh-credential: "{jenkins-ssh-credential}"
171           git-url: "{git-url}"
172           refspec: "$GERRIT_REFSPEC"
173           branch: "$GERRIT_BRANCH"
174           submodule-recursive: "{submodule-recursive}"
175           submodule-timeout: "{submodule-timeout}"
176           submodule-disable: "{submodule-disable}"
177           choosing-strategy: default
178
179     triggers:
180       - timed: "{obj:cron}"
181       - gerrit:
182           server-name: "{gerrit-server-name}"
183           trigger-on: "{obj:gerrit_nexus_iq_triggers}"
184           projects:
185             - project-compare-type: ANT
186               project-pattern: "{project}"
187               branches:
188                 - branch-compare-type: ANT
189                   branch-pattern: "**/{branch}"
190           skip-vote:
191             successful: true
192             failed: true
193             unstable: true
194             notbuilt: true
195
196 - job-template:
197     name: "{project-name}-tox-nexus-iq"
198     id: github-tox-nexus-iq-clm
199     <<: *lf_python_common
200     <<: *lf_tox_nexus_iq_clm
201
202     properties:
203       - lf-infra-properties:
204           build-days-to-keep: "{build-days-to-keep}"
205       - github:
206           url: "{github-url}/{github-org}/{project}"
207
208     scm:
209       - lf-infra-github-scm:
210           url: "{git-clone-url}{github-org}/{project}"
211           refspec: ""
212           branch: "refs/heads/{branch}"
213           submodule-recursive: "{submodule-recursive}"
214           submodule-timeout: "{submodule-timeout}"
215           submodule-disable: "{submodule-disable}"
216           choosing-strategy: default
217           jenkins-ssh-credential: "{jenkins-ssh-credential}"
218
219     triggers:
220       - timed: "{obj:cron}"
221       - github-pull-request:
222           trigger-phrase: "^run-clm$"
223           only-trigger-phrase: false
224           status-context: "CLM"
225           permit-all: true
226           github-hooks: true
227           white-list-target-branches:
228             - "{branch}"
229
230 ###################
231 # Python Snyk CLI #
232 ###################
233
234 - _lf_python_snyk_cli: &lf_python_snyk_cli
235     name: lf-python-snyk_cli
236
237     ######################
238     # Default parameters #
239     ######################
240
241     branch: master
242     build-days-to-keep: 30 # 30 days for troubleshooting purposes
243     build-timeout: 60
244     disable-job: false
245     git-url: "$GIT_URL/$PROJECT"
246     github-url: "https://github.com"
247     java-version: openjdk11
248     parallel: false
249     pre-build-script: "# pre-build script goes here"
250     python-version: python3
251     snyk-cli-options: ""
252     snyk-token-credential-id: snyk-token
253     snyk-org-credential-id: snyk-org
254     stream: master
255     submodule-recursive: true
256     submodule-timeout: 10
257     submodule-disable: false
258     tox-dir: "."
259     tox-envs: ""
260
261     gerrit_snyk_triggers:
262       - comment-added-contains-event:
263           comment-contains-value: '^Patch Set\s+\d+:\s+run-snyk\s*$'
264
265     parameters:
266       - lf-infra-parameters:
267           project: "{project}"
268           branch: "{branch}"
269           stream: "{stream}"
270       - string:
271           name: SNYK_CLI_OPTIONS
272           default: "{snyk-cli-options}"
273           description: Additional Snyk CLI commands and options
274       - lf-infra-tox-parameters:
275           tox-dir: "{tox-dir}"
276           tox-envs: "{tox-envs}"
277
278     wrappers:
279       - credentials-binding:
280           - text:
281               credential-id: "{snyk-token-credential-id}"
282               variable: SNYK_TOKEN
283           - text:
284               credential-id: "{snyk-org-credential-id}"
285               variable: SNYK_ORG
286
287     #####################
288     # Job Configuration #
289     #####################
290
291     disabled: "{disable-job}"
292
293     builders:
294       - lf-infra-pre-build
295       - lf-infra-tox-install:
296           python-version: "{python-version}"
297       - shell: "{pre-build-script}"
298       - lf-infra-tox-run:
299           parallel: "{parallel}"
300       - lf-infra-snyk-cli-scanner
301
302 - job-template:
303     name: "{project-name}-python-snyk-cli-{stream}"
304     id: gerrit-python-snyk-cli
305     # yamllint disable-line rule:key-duplicates
306     <<: *lf_python_snyk_cli
307
308     scm:
309       - lf-infra-gerrit-scm:
310           jenkins-ssh-credential: "{jenkins-ssh-credential}"
311           git-url: "{git-url}"
312           refspec: "$GERRIT_REFSPEC"
313           branch: "$GERRIT_BRANCH"
314           submodule-recursive: "{submodule-recursive}"
315           submodule-timeout: "{submodule-timeout}"
316           submodule-disable: "{submodule-disable}"
317           choosing-strategy: default
318
319     triggers:
320       # Build weekly on Saturdays
321       - timed: "H H * * 6"
322       - gerrit:
323           server-name: "{gerrit-server-name}"
324           trigger-on: "{obj:gerrit_snyk_triggers}"
325           projects:
326             - project-compare-type: ANT
327               project-pattern: "{project}"
328               branches:
329                 - branch-compare-type: ANT
330                   branch-pattern: "**/{branch}"
331           skip-vote:
332             successful: true
333             failed: true
334             unstable: true
335             notbuilt: true
336
337 - job-template:
338     name: "{project-name}-python-snyk-cli-{stream}"
339     id: github-python-snyk-cli
340     # yamllint disable-line rule:key-duplicates
341     <<: *lf_python_snyk_cli
342
343     properties:
344       - lf-infra-properties:
345           build-days-to-keep: "{build-days-to-keep}"
346       - github:
347           url: "{github-url}/{github-org}/{project}"
348
349     scm:
350       - lf-infra-github-scm:
351           url: "{git-clone-url}{github-org}/{project}"
352           refspec: ""
353           branch: "refs/heads/{branch}"
354           submodule-recursive: "{submodule-recursive}"
355           submodule-timeout: "{submodule-timeout}"
356           submodule-disable: "{submodule-disable}"
357           choosing-strategy: default
358           jenkins-ssh-credential: "{jenkins-ssh-credential}"
359
360     triggers:
361       # Build weekly on Saturdays
362       - timed: "H H * * 6"
363       - github-pull-request:
364           trigger-phrase: "^run-snyk$"
365           only-trigger-phrase: true
366           status-context: "SNYK scan"
367           permit-all: true
368           github-hooks: true
369           org-list:
370             - "{github-org}"
371           white-list: "{obj:github_pr_allowlist}"
372           admin-list: "{obj:github_pr_admin_list}"
373           white-list-target-branches:
374             - "{branch}"
375
376 #########################
377 # Python Sonar with CLI #
378 #########################
379
380 - _lf_cli_sonar: &lf_cli_sonar
381     name: lf-cli-sonar
382
383     ######################
384     # Default parameters #
385     ######################
386
387     branch: master # Sonar should always be run on master branch
388     build-days-to-keep: 7
389     build-timeout: 60
390     cron: "H H * * *" # run daily
391     disable-job: false
392     git-url: "$GIT_URL/$PROJECT"
393     github-url: "https://github.com"
394     # SonarCloud scan using jdk8 will become deprecated by Oct, 2020
395     # Projects not compatible with jdk11 can set java-version to something else
396     java-version: openjdk11
397     parallel: true
398     pre-build-script: "# pre-build script goes here"
399     python-version: python3
400     stream: master
401     sonar-scanner-version: "4.7.0.2747"
402     sonar-scanner-home: "$WORKSPACE/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux"
403     sonar-scanner-opts: "-server"
404     submodule-recursive: true
405     submodule-timeout: 10
406     submodule-disable: false
407     tox-dir: "."
408     tox-envs: ""
409
410     gerrit_trigger_file_paths:
411       - compare-type: REG_EXP
412         pattern: ".*"
413
414     # github_included_regions MUST match gerrit_trigger_file_paths
415     github_included_regions:
416       - ".*"
417
418     #####################
419     # Job Configuration #
420     #####################
421
422     disabled: "{disable-job}"
423
424     parameters:
425       - lf-infra-parameters:
426           project: "{project}"
427           branch: "{branch}"
428           stream: "{stream}"
429       - lf-infra-sonar-cli-parameters:
430           tox-dir: "{tox-dir}"
431           tox-envs: "{tox-envs}"
432           sonar-scanner-version: "{sonar-scanner-version}"
433           sonar-scanner-home: "{sonar-scanner-home}"
434           sonar-scanner-opts: "{sonar-scanner-opts}"
435       - string:
436           name: ARCHIVE_ARTIFACTS
437           default: "{archive-artifacts}"
438           description: Artifacts to archive to the logs server.
439     wrappers:
440       - credentials-binding:
441           - text:
442               credential-id: sonar-token-{project-name}
443               variable: SONAR_TOKEN
444     builders:
445       - lf-infra-pre-build
446       - lf-infra-tox-install:
447           python-version: "{python-version}"
448       - shell: "{pre-build-script}"
449       - lf-infra-tox-run:
450           parallel: "{parallel}"
451       # With Sonar CLI
452       - inject:
453           properties-content: |
454             SONARCLOUD_PROJECT_ORGANIZATION={sonarcloud-project-organization}
455             SONARCLOUD_PROJECT_KEY={sonarcloud-project-key}
456       - shell: !include-raw-escape: ../shell/sonar-cli.sh
457
458     publishers:
459       - lf-infra-publish
460
461 - job-template:
462     name: "{project-name}-cli-sonar"
463     id: gerrit-cli-sonar
464     <<: *lf_python_common
465     <<: *lf_cli_sonar
466
467     ######################
468     # Default parameters #
469     ######################
470
471     gerrit_sonar_triggers:
472       - comment-added-contains-event:
473           comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$'
474
475     #####################
476     # Job Configuration #
477     #####################
478
479     scm:
480       - lf-infra-gerrit-scm:
481           jenkins-ssh-credential: "{jenkins-ssh-credential}"
482           git-url: "{git-url}"
483           refspec: $GERRIT_REFSPEC
484           branch: $GERRIT_BRANCH
485           submodule-recursive: "{submodule-recursive}"
486           submodule-timeout: "{submodule-timeout}"
487           submodule-disable: "{submodule-disable}"
488           choosing-strategy: default
489
490     triggers:
491       - timed: "{obj:cron}"
492       - gerrit:
493           server-name: "{gerrit-server-name}"
494           trigger-on: "{obj:gerrit_sonar_triggers}"
495           projects:
496             - project-compare-type: "ANT"
497               project-pattern: "{project}"
498               branches:
499                 - branch-compare-type: "ANT"
500                   branch-pattern: "**/{branch}"
501               file-paths: "{obj:gerrit_trigger_file_paths}"
502           skip-vote:
503             successful: true
504             failed: true
505             unstable: true
506             notbuilt: true
507
508 - job-template:
509     name: "{project-name}-cli-sonar"
510     id: github-cli-sonar
511     <<: *lf_python_common
512     <<: *lf_cli_sonar
513
514     properties:
515       - lf-infra-properties:
516           build-days-to-keep: "{build-days-to-keep}"
517       - github:
518           url: "{github-url}/{github-org}/{project}"
519
520     scm:
521       - lf-infra-github-scm:
522           url: "{git-clone-url}{github-org}/{project}"
523           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
524           branch: "$sha1"
525           submodule-recursive: "{submodule-recursive}"
526           submodule-timeout: "{submodule-timeout}"
527           submodule-disable: "{submodule-disable}"
528           choosing-strategy: default
529           jenkins-ssh-credential: "{jenkins-ssh-credential}"
530
531     triggers:
532       - github-pull-request:
533           trigger-phrase: "^run-sonar$"
534           only-trigger-phrase: false
535           status-context: "Python Sonar"
536           permit-all: true
537           github-hooks: true
538           white-list-target-branches:
539             - "{branch}"
540           included-regions: "{obj:github_included_regions}"
541
542 #########################
543 # Python Sonar with Tox #
544 #########################
545
546 - _lf_tox_sonar: &lf_tox_sonar
547     name: lf-tox-sonar
548
549     ######################
550     # Default parameters #
551     ######################
552
553     branch: master # Sonar should always be run on master branch
554     build-days-to-keep: 7
555     build-timeout: 60
556     cron: "H H * * *" # run daily
557     disable-job: false
558     git-url: "$GIT_URL/$PROJECT"
559     github-url: "https://github.com"
560     java-version: openjdk11
561     mvn-global-settings: global-settings
562     mvn-goals: validate
563     mvn-opts: ""
564     mvn-params: ""
565     mvn-settings: ""
566     mvn-version: mvn35
567     parallel: true
568     pre-build-script: "# pre-build script goes here"
569     python-version: python3
570     sonar-mvn-goal: "sonar:sonar"
571     sonarcloud: false
572     sonarcloud-project-key: ""
573     sonarcloud-project-organization: ""
574     sonarcloud-api-token-cred-id: sonarcloud-api-token
575     sonarcloud-qualitygate-wait: false
576     # Projects not compatible with jdk17 can set java-version to something else
577     sonarcloud-java-version: openjdk17
578     stream: master
579     submodule-recursive: true
580     submodule-timeout: 10
581     submodule-disable: false
582     tox-dir: "."
583     tox-envs: ""
584     scan-dev-branch: false
585
586     gerrit_trigger_file_paths:
587       - compare-type: REG_EXP
588         pattern: ".*"
589
590     # github_included_regions MUST match gerrit_trigger_file_paths
591     github_included_regions:
592       - ".*"
593
594     #####################
595     # Job Configuration #
596     #####################
597
598     disabled: "{disable-job}"
599
600     parameters:
601       - lf-infra-parameters:
602           project: "{project}"
603           branch: "{branch}"
604           stream: "{stream}"
605       - lf-infra-maven-parameters:
606           mvn-opts: "{mvn-opts}"
607           mvn-params: "{mvn-params}"
608           mvn-version: "{mvn-version}"
609       - lf-infra-tox-parameters:
610           tox-dir: "{tox-dir}"
611           tox-envs: "{tox-envs}"
612       - string:
613           name: ARCHIVE_ARTIFACTS
614           default: "{archive-artifacts}"
615           description: Artifacts to archive to the logs server.
616       - string:
617           name: MVN
618           # Sets an env var for shell scripts to be able to call the dynamically
619           # installed maven without having to calculate the path themselves.
620           # yamllint disable-line rule:line-length
621           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn"
622           description: "Maven selector to be used by shell scripts"
623       - string:
624           name: SONAR_MAVEN_GOAL
625           default: "{sonar-mvn-goal}"
626           description: |
627             Maven goals to pass to the Sonar call. Typically sonar:sonar
628             however to use a specific version of the sonar-maven-plugin we
629             can call "org.codehaus.mojo:sonar-maven-plugin:3.3.0.603:sonar".
630
631     wrappers:
632       - credentials-binding:
633           - text:
634               credential-id: "{sonarcloud-api-token-cred-id}"
635               variable: API_TOKEN
636
637     builders:
638       - lf-infra-pre-build
639       - lf-infra-tox-install:
640           python-version: "{python-version}"
641       - shell: "{pre-build-script}"
642       - lf-infra-tox-run:
643           parallel: "{parallel}"
644       - lf-provide-maven-settings:
645           global-settings-file: "{mvn-global-settings}"
646           settings-file: "{mvn-settings}"
647       # With SonarCloud
648       - conditional-step:
649           condition-kind: boolean-expression
650           condition-expression: "{sonarcloud}"
651           steps:
652             - shell: echo 'Using SonarCloud'
653             - lf-infra-maven-sonarcloud:
654                 java-version: "{java-version}"
655                 mvn-goals: "{mvn-goals}"
656                 mvn-settings: "{mvn-settings}"
657                 mvn-version: "{mvn-version}"
658                 sonarcloud-project-key: "{sonarcloud-project-key}"
659                 # yamllint disable-line rule:line-length
660                 sonarcloud-project-organization: "{sonarcloud-project-organization}"
661                 sonarcloud-java-version: "{sonarcloud-java-version}"
662                 sonarcloud-qualitygate-wait: "{sonarcloud-qualitygate-wait}"
663                 scan-dev-branch: "{scan-dev-branch}"
664       # With SonarQube
665       - conditional-step:
666           condition-kind: not
667           condition-operand:
668             condition-kind: boolean-expression
669             condition-expression: "{sonarcloud}"
670           steps:
671             - shell: echo 'Using SonarQube'
672             - lf-infra-maven-sonar:
673                 java-version: "{java-version}"
674                 mvn-goals: "{mvn-goals}"
675                 mvn-settings: "{mvn-settings}"
676                 mvn-version: "{mvn-version}"
677
678     publishers:
679       - lf-infra-publish
680
681 - job-template:
682     name: "{project-name}-tox-sonar"
683     id: gerrit-tox-sonar
684     <<: *lf_python_common
685     <<: *lf_tox_sonar
686
687     ######################
688     # Default parameters #
689     ######################
690
691     gerrit_sonar_triggers:
692       - comment-added-contains-event:
693           comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$'
694
695     #####################
696     # Job Configuration #
697     #####################
698
699     scm:
700       - lf-infra-gerrit-scm:
701           jenkins-ssh-credential: "{jenkins-ssh-credential}"
702           git-url: "{git-url}"
703           refspec: $GERRIT_REFSPEC
704           branch: $GERRIT_BRANCH
705           submodule-recursive: "{submodule-recursive}"
706           submodule-timeout: "{submodule-timeout}"
707           submodule-disable: "{submodule-disable}"
708           choosing-strategy: default
709
710     triggers:
711       - timed: "{obj:cron}"
712       - gerrit:
713           server-name: "{gerrit-server-name}"
714           trigger-on: "{obj:gerrit_sonar_triggers}"
715           projects:
716             - project-compare-type: "ANT"
717               project-pattern: "{project}"
718               branches:
719                 - branch-compare-type: "ANT"
720                   branch-pattern: "**/{branch}"
721               file-paths: "{obj:gerrit_trigger_file_paths}"
722           skip-vote:
723             successful: true
724             failed: true
725             unstable: true
726             notbuilt: true
727
728 - job-template:
729     name: "{project-name}-tox-sonar"
730     id: github-tox-sonar
731     <<: *lf_python_common
732     <<: *lf_tox_sonar
733
734     properties:
735       - lf-infra-properties:
736           build-days-to-keep: "{build-days-to-keep}"
737       - github:
738           url: "{github-url}/{github-org}/{project}"
739
740     scm:
741       - lf-infra-github-scm:
742           url: "{git-clone-url}{github-org}/{project}"
743           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
744           branch: "$sha1"
745           submodule-recursive: "{submodule-recursive}"
746           submodule-timeout: "{submodule-timeout}"
747           submodule-disable: "{submodule-disable}"
748           choosing-strategy: default
749           jenkins-ssh-credential: "{jenkins-ssh-credential}"
750
751     triggers:
752       - github-pull-request:
753           trigger-phrase: "^run-sonar$"
754           only-trigger-phrase: false
755           status-context: "Python Sonar"
756           permit-all: true
757           github-hooks: true
758           white-list-target-branches:
759             - "{branch}"
760           included-regions: "{obj:github_included_regions}"
761
762 #################
763 # Tox SonarQube #
764 #################
765
766 - _lf_tox_sonarqube: &lf_tox_sonarqube
767     name: lf-tox-sonarqube
768
769     ######################
770     # Default parameters #
771     ######################
772
773     archive-artifacts: >
774       **/*.log
775     branch: master # Sonar should always be run on master branch
776     build-days-to-keep: 7
777     build-timeout: 15
778     cron: "@weekly"
779     disable-job: false
780     git-url: "$GIT_URL/$PROJECT"
781     github-url: "https://github.com"
782     java-version: openjdk17
783     parallel: false
784     pre-build-script: "# pre-build script goes here"
785     python-version: python3
786     stream: master
787     submodule-recursive: true
788     submodule-timeout: 10
789     submodule-disable: false
790     tox-dir: "."
791     tox-envs: ""
792     # Sonar properties
793     sonar-additional-args: ""
794     sonar-java-opts: ""
795     sonar-project-file: "sonar-project.properties"
796     sonar-properties: ""
797     sonar-task: ""
798     sonar-jdk: openjdk17
799
800     #####################
801     # Job Configuration #
802     #####################
803
804     project-type: freestyle
805     node: "{build-node}"
806     disabled: "{disable-job}"
807
808     properties:
809       - lf-infra-properties:
810           build-days-to-keep: "{build-days-to-keep}"
811
812     wrappers:
813       - lf-infra-wrappers:
814           build-timeout: "{build-timeout}"
815           jenkins-ssh-credential: "{jenkins-ssh-credential}"
816
817     parameters:
818       - lf-infra-parameters:
819           project: "{project}"
820           branch: "{branch}"
821           stream: "{stream}"
822       - lf-infra-tox-parameters:
823           tox-dir: "{tox-dir}"
824           tox-envs: "{tox-envs}"
825       - string:
826           name: ARCHIVE_ARTIFACTS
827           default: "{archive-artifacts}"
828           description: Artifacts to archive to the logs server.
829
830     builders:
831       - lf-infra-pre-build
832       - lf-update-java-alternatives:
833           java-version: "{java-version}"
834       - lf-infra-tox-install:
835           python-version: "{python-version}"
836       - shell: "{pre-build-script}"
837       - lf-infra-tox-run:
838           parallel: "{parallel}"
839       - lf-infra-sonar:
840           sonar-task: "{sonar-task}"
841           sonar-project-file: "{sonar-project-file}"
842           sonar-properties: "{sonar-properties}"
843           sonar-java-opts: "{sonar-java-opts}"
844           sonar-additional-args: "{sonar-additional-args}"
845           sonar-jdk: "{sonar-jdk}"
846
847     publishers:
848       - lf-infra-publish
849
850 - job-template:
851     name: "{project-name}-tox-sonarqube"
852     id: gerrit-tox-sonarqube
853     concurrent: false
854     <<: *lf_tox_sonarqube
855
856     ######################
857     # Default parameters #
858     ######################
859
860     gerrit_sonar_triggers:
861       - comment-added-contains-event:
862           comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$'
863
864     scm:
865       - lf-infra-gerrit-scm:
866           branch: "$GERRIT_BRANCH"
867           jenkins-ssh-credential: "{jenkins-ssh-credential}"
868           git-url: "{git-url}"
869           refspec: "$GERRIT_REFSPEC"
870           submodule-recursive: "{submodule-recursive}"
871           submodule-timeout: "{submodule-timeout}"
872           submodule-disable: "{submodule-disable}"
873           choosing-strategy: default
874
875     triggers:
876       - timed: "{obj:cron}"
877       - gerrit:
878           server-name: "{gerrit-server-name}"
879           trigger-on: "{obj:gerrit_sonar_triggers}"
880           projects:
881             - project-compare-type: "ANT"
882               project-pattern: "{project}"
883               branches:
884                 - branch-compare-type: "ANT"
885                   branch-pattern: "**/{branch}"
886
887 - job-template:
888     name: "{project-name}-tox-sonarqube"
889     id: github-tox-sonarqube
890     concurrent: false
891     <<: *lf_tox_sonarqube
892
893     scm:
894       - lf-infra-github-scm:
895           branch: "$sha1"
896           jenkins-ssh-credential: "{jenkins-ssh-credential}"
897           url: "{git-clone-url}{github-org}/{project}"
898           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
899           submodule-recursive: "{submodule-recursive}"
900           submodule-timeout: "{submodule-timeout}"
901           submodule-disable: "{submodule-disable}"
902           choosing-strategy: default
903
904     triggers:
905       - github-pull-request:
906           trigger-phrase: "^run-sonar$"
907           only-trigger-phrase: false
908           status-context: "Tox Sonarqube"
909           permit-all: true
910           github-hooks: true
911           white-list-target-branches:
912             - "{branch}"
913
914 ##############
915 # Tox Common #
916 ##############
917
918 - _lf_tox_common: &lf_tox_common
919     name: lf-tox-common
920
921     ######################
922     # Default parameters #
923     ######################
924
925     branch: master
926     build-days-to-keep: 7
927     build-timeout: 15
928     disable-job: false
929     git-url: "$GIT_URL/$GERRIT_PROJECT"
930     github-url: "https://github.com"
931     parallel: false
932     pre-build-script: "# pre-build script goes here"
933     python-version: python3
934     stream: master
935     submodule-recursive: true
936     submodule-timeout: 10
937     submodule-disable: false
938     tox-dir: "."
939     tox-envs: ""
940
941     gerrit_trigger_file_paths:
942       - compare-type: REG_EXP
943         pattern: ".*"
944
945     # github_included_regions MUST match gerrit_trigger_file_paths
946     github_included_regions:
947       - ".*"
948
949     #####################
950     # Job Configuration #
951     #####################
952
953     project-type: freestyle
954     node: "{build-node}"
955     concurrent: true
956     disabled: "{disable-job}"
957
958     properties:
959       - lf-infra-properties:
960           build-days-to-keep: "{build-days-to-keep}"
961
962     parameters:
963       - lf-infra-parameters:
964           project: "{project}"
965           branch: "{branch}"
966           stream: "{stream}"
967       - lf-infra-tox-parameters:
968           tox-dir: "{tox-dir}"
969           tox-envs: "{tox-envs}"
970
971     wrappers:
972       - lf-infra-wrappers:
973           build-timeout: "{build-timeout}"
974           jenkins-ssh-credential: "{jenkins-ssh-credential}"
975
976     builders:
977       - lf-infra-pre-build
978       - lf-infra-tox-install:
979           python-version: "{python-version}"
980       - shell: "{pre-build-script}"
981       - lf-infra-tox-run:
982           parallel: "{parallel}"
983
984     publishers:
985       - lf-infra-publish
986
987 - job-template:
988     # Python projects typically use tox to run testing.
989     name: "{project-name}-tox-verify-{stream}"
990     id: gerrit-tox-verify
991     <<: *lf_tox_common
992
993     ######################
994     # Default parameters #
995     ######################
996
997     gerrit-skip-vote: false
998     gerrit_verify_triggers:
999       - patchset-created-event:
1000           exclude-drafts: true
1001           exclude-trivial-rebase: false
1002           exclude-no-code-change: false
1003       - draft-published-event
1004       - comment-added-contains-event:
1005           comment-contains-value: '^Patch Set\s+\d+:\s+(recheck|reverify)\s*$'
1006
1007     #####################
1008     # Job Configuration #
1009     #####################
1010
1011     scm:
1012       - lf-infra-gerrit-scm:
1013           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1014           git-url: "{git-url}"
1015           refspec: "$GERRIT_REFSPEC"
1016           branch: "$GERRIT_BRANCH"
1017           submodule-recursive: "{submodule-recursive}"
1018           submodule-timeout: "{submodule-timeout}"
1019           submodule-disable: "{submodule-disable}"
1020           choosing-strategy: gerrit
1021
1022     triggers:
1023       - gerrit:
1024           server-name: "{gerrit-server-name}"
1025           trigger-on: "{obj:gerrit_verify_triggers}"
1026           projects:
1027             - project-compare-type: ANT
1028               project-pattern: "{project}"
1029               branches:
1030                 - branch-compare-type: ANT
1031                   branch-pattern: "**/{branch}"
1032               file-paths: "{obj:gerrit_trigger_file_paths}"
1033           skip-vote:
1034             successful: "{gerrit-skip-vote}"
1035             failed: "{gerrit-skip-vote}"
1036             unstable: "{gerrit-skip-vote}"
1037             notbuilt: "{gerrit-skip-vote}"
1038
1039 - job-template:
1040     # Python projects typically use tox to run testing.
1041     name: "{project-name}-tox-verify-{stream}"
1042     id: github-tox-verify
1043     <<: *lf_tox_common
1044
1045     properties:
1046       - lf-infra-properties:
1047           build-days-to-keep: "{build-days-to-keep}"
1048       - github:
1049           url: "{github-url}/{github-org}/{project}"
1050
1051     scm:
1052       - lf-infra-github-scm:
1053           url: "{git-clone-url}{github-org}/{project}"
1054           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
1055           branch: "$sha1"
1056           submodule-recursive: "{submodule-recursive}"
1057           submodule-timeout: "{submodule-timeout}"
1058           submodule-disable: "{submodule-disable}"
1059           choosing-strategy: default
1060           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1061
1062     triggers:
1063       - github-pull-request:
1064           trigger-phrase: "^(recheck|reverify)$"
1065           only-trigger-phrase: false
1066           status-context: "Tox Verify"
1067           permit-all: true
1068           github-hooks: true
1069           white-list-target-branches:
1070             - "{branch}"
1071           included-regions: "{obj:github_included_regions}"
1072
1073 - job-template:
1074     # Run tox after merge of gerrit change set
1075     name: "{project-name}-tox-merge-{stream}"
1076     id: gerrit-tox-merge
1077     <<: *lf_tox_common
1078
1079     ######################
1080     # Default parameters #
1081     ######################
1082
1083     gerrit_merge_triggers:
1084       - change-merged-event
1085       - comment-added-contains-event:
1086           comment-contains-value: '^Patch Set\s+\d+:\s+remerge\s*$'
1087
1088     #####################
1089     # Job Configuration #
1090     #####################
1091
1092     scm:
1093       - lf-infra-gerrit-scm:
1094           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1095           git-url: "{git-url}"
1096           refspec: "$GERRIT_REFSPEC"
1097           branch: "$GERRIT_BRANCH"
1098           submodule-recursive: "{submodule-recursive}"
1099           submodule-timeout: "{submodule-timeout}"
1100           submodule-disable: "{submodule-disable}"
1101           # merge jobs always build from tip
1102           choosing-strategy: default
1103
1104     triggers:
1105       - gerrit:
1106           server-name: "{gerrit-server-name}"
1107           trigger-on: "{obj:gerrit_merge_triggers}"
1108           projects:
1109             - project-compare-type: ANT
1110               project-pattern: "{project}"
1111               branches:
1112                 - branch-compare-type: ANT
1113                   branch-pattern: "**/{branch}"
1114               file-paths: "{obj:gerrit_trigger_file_paths}"
1115
1116 - job-template:
1117     # Run tox after merge of github pull request
1118     name: "{project-name}-tox-merge-{stream}"
1119     id: github-tox-merge
1120     <<: *lf_tox_common
1121
1122     properties:
1123       - lf-infra-properties:
1124           build-days-to-keep: "{build-days-to-keep}"
1125       - github:
1126           url: "{github-url}/{github-org}/{project}"
1127
1128     scm:
1129       - lf-infra-github-scm:
1130           url: "{git-clone-url}{github-org}/{project}"
1131           refspec: ""
1132           branch: "refs/heads/{branch}"
1133           submodule-recursive: "{submodule-recursive}"
1134           submodule-timeout: "{submodule-timeout}"
1135           submodule-disable: "{submodule-disable}"
1136           choosing-strategy: default
1137           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1138
1139     triggers:
1140       - github-pull-request:
1141           trigger-phrase: "^remerge$"
1142           only-trigger-phrase: true
1143           status-context: "Tox Merge"
1144           permit-all: true
1145           github-hooks: true
1146           org-list:
1147             - "{github-org}"
1148           white-list: "{obj:github_pr_allowlist}"
1149           admin-list: "{obj:github_pr_admin_list}"
1150           white-list-target-branches:
1151             - "{branch}"
1152           included-regions: "{obj:github_included_regions}"
1153
1154 ########
1155 # PyPI #
1156 ########
1157
1158 - _lf_pypi_common: &lf_pypi_common
1159     name: lf-pypi-common
1160
1161     ######################
1162     # Default parameters #
1163     ######################
1164
1165     archive-artifacts: >
1166       **/*.log
1167     branch: master
1168     build-days-to-keep: 7
1169     build-timeout: 15
1170     disable-job: false
1171     dist-binary: true
1172     git-url: "$GIT_URL/$GERRIT_PROJECT"
1173     github-url: "https://github.com"
1174     parallel: false
1175     pre-build-script: "# pre-build script goes here"
1176     python-version: python3
1177     stream: master
1178     submodule-disable: false
1179     submodule-recursive: true
1180     submodule-timeout: 10
1181     tox-dir: "."
1182     tox-envs: ""
1183
1184     gerrit_trigger_file_paths:
1185       - compare-type: REG_EXP
1186         pattern: ".*"
1187
1188     # github_included_regions MUST match gerrit_trigger_file_paths
1189     github_included_regions:
1190       - ".*"
1191
1192     #####################
1193     # Job Configuration #
1194     #####################
1195
1196     project-type: freestyle
1197     node: "{build-node}"
1198     disabled: "{disable-job}"
1199
1200     properties:
1201       - lf-infra-properties:
1202           build-days-to-keep: "{build-days-to-keep}"
1203
1204     parameters:
1205       - lf-infra-parameters:
1206           project: "{project}"
1207           branch: "{branch}"
1208           stream: "{stream}"
1209       - lf-infra-tox-parameters:
1210           tox-dir: "{tox-dir}"
1211           tox-envs: "{tox-envs}"
1212       - bool:
1213           name: BUILD_BDIST_WHEEL
1214           default: "{dist-binary}"
1215           description: "Set to True (checked) to build a binary distribution"
1216       - bool:
1217           name: DRY_RUN
1218           default: false
1219           description: "Set to True (checked) to skip uploading artifacts"
1220
1221     wrappers:
1222       - lf-infra-wrappers:
1223           build-timeout: "{build-timeout}"
1224           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1225
1226     publishers:
1227       - lf-infra-publish
1228
1229 - _lf_pypi_verify_builders: &lf_pypi_verify_builders
1230     name: lf-pypi-verify-builders
1231
1232     builders:
1233       - lf-infra-pre-build
1234       - lf-infra-tox-install:
1235           python-version: "{python-version}"
1236       - shell: "{pre-build-script}"
1237       - lf-infra-tox-run:
1238           parallel: "{parallel}"
1239       - shell: !include-raw-escape: ../shell/pypi-dist-build.sh
1240
1241 - _lf_pypi_publish_builders: &lf_pypi_publish_builders
1242     name: lf-pypi-publish-builders
1243
1244     builders:
1245       - lf-infra-pre-build
1246       - lf-infra-tox-install:
1247           python-version: "{python-version}"
1248       - shell: "{pre-build-script}"
1249       - lf-infra-tox-run:
1250           parallel: "{parallel}"
1251       - shell: !include-raw-escape: ../shell/pypi-dist-build.sh
1252       - config-file-provider:
1253           files:
1254             - file-id: pypirc
1255               target: "$HOME/.pypirc"
1256       - inject:
1257           properties-content: "REPOSITORY={pypi-repo}"
1258       - shell: !include-raw-escape: ../shell/pypi-upload.sh
1259
1260 - job-template:
1261     name: "{project-name}-pypi-verify-{stream}"
1262     id: gerrit-pypi-verify
1263     <<: *lf_pypi_common
1264     <<: *lf_pypi_verify_builders
1265
1266     scm:
1267       - lf-infra-gerrit-scm:
1268           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1269           git-url: "{git-url}"
1270           refspec: "$GERRIT_REFSPEC"
1271           branch: "$GERRIT_BRANCH"
1272           submodule-recursive: "{submodule-recursive}"
1273           submodule-timeout: "{submodule-timeout}"
1274           submodule-disable: "{submodule-disable}"
1275           choosing-strategy: gerrit
1276
1277     triggers:
1278       - gerrit:
1279           server-name: "{gerrit-server-name}"
1280           trigger-on:
1281             - patchset-created-event:
1282                 exclude-drafts: true
1283                 exclude-trivial-rebase: false
1284                 exclude-no-code-change: false
1285             - draft-published-event
1286             - comment-added-contains-event:
1287                 # yamllint disable-line rule:line-length
1288                 comment-contains-value: '^Patch Set\s+\d+:\s+(recheck|reverify)\s*$'
1289           projects:
1290             - project-compare-type: ANT
1291               project-pattern: "{project}"
1292               branches:
1293                 - branch-compare-type: ANT
1294                   branch-pattern: "**/{branch}"
1295               file-paths: "{obj:gerrit_trigger_file_paths}"
1296
1297 - job-template:
1298     name: "{project-name}-pypi-verify-{stream}"
1299     id: github-pypi-verify
1300     <<: *lf_pypi_common
1301     <<: *lf_pypi_verify_builders
1302
1303     properties:
1304       - github:
1305           url: "{github-url}/{github-org}/{project}"
1306
1307     scm:
1308       - lf-infra-github-scm:
1309           url: "{git-clone-url}{github-org}/{project}"
1310           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
1311           branch: "$sha1"
1312           submodule-recursive: "{submodule-recursive}"
1313           submodule-timeout: "{submodule-timeout}"
1314           submodule-disable: "{submodule-disable}"
1315           choosing-strategy: default
1316           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1317
1318     triggers:
1319       - github-pull-request:
1320           trigger-phrase: "^(recheck|reverify)$"
1321           only-trigger-phrase: false
1322           status-context: "PyPI Verify"
1323           permit-all: true
1324           github-hooks: true
1325           white-list-target-branches:
1326             - "{branch}"
1327           included-regions: "{obj:github_included_regions}"
1328
1329 - job-template:
1330     name: "{project-name}-pypi-merge-{stream}"
1331     id: gerrit-pypi-merge
1332     <<: *lf_pypi_common
1333     <<: *lf_pypi_publish_builders
1334
1335     cron: "" # avoid for pypi which rejects duplicates
1336     pypi-repo: pypi-test
1337
1338     scm:
1339       - lf-infra-gerrit-scm:
1340           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1341           git-url: "{git-url}"
1342           refspec: "$GERRIT_REFSPEC"
1343           branch: "$GERRIT_BRANCH"
1344           submodule-recursive: "{submodule-recursive}"
1345           submodule-timeout: "{submodule-timeout}"
1346           submodule-disable: "{submodule-disable}"
1347           # merge jobs always build from tip
1348           choosing-strategy: default
1349
1350     triggers:
1351       - timed: "{obj:cron}"
1352       - gerrit:
1353           server-name: "{gerrit-server-name}"
1354           trigger-on:
1355             - change-merged-event
1356             - comment-added-contains-event:
1357                 comment-contains-value: '^Patch Set\s+\d+:\s+remerge\s*$'
1358           projects:
1359             - project-compare-type: ANT
1360               project-pattern: "{project}"
1361               branches:
1362                 - branch-compare-type: ANT
1363                   branch-pattern: "**/{branch}"
1364               file-paths: "{obj:gerrit_trigger_file_paths}"
1365
1366 - job-template:
1367     name: "{project-name}-pypi-merge-{stream}"
1368     id: github-pypi-merge
1369     <<: *lf_pypi_common
1370     <<: *lf_pypi_publish_builders
1371
1372     cron: ""
1373     pypi-repo: pypi-test
1374
1375     properties:
1376       - github:
1377           url: "{github-url}/{github-org}/{project}"
1378
1379     scm:
1380       - lf-infra-github-scm:
1381           url: "{git-clone-url}{github-org}/{project}"
1382           refspec: ""
1383           branch: "refs/heads/{branch}"
1384           submodule-recursive: "{submodule-recursive}"
1385           submodule-timeout: "{submodule-timeout}"
1386           submodule-disable: "{submodule-disable}"
1387           choosing-strategy: default
1388           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1389
1390     triggers:
1391       - timed: "{obj:cron}"
1392       - github-pull-request:
1393           trigger-phrase: "^remerge$"
1394           only-trigger-phrase: false
1395           status-context: "Merge"
1396           permit-all: true
1397           github-hooks: true
1398           org-list:
1399             - "{github-org}"
1400           white-list: "{obj:github_pr_allowlist}"
1401           admin-list: "{obj:github_pr_admin_list}"
1402           white-list-target-branches:
1403             - "{branch}"
1404           included-regions: "{obj:github_included_regions}"
1405
1406 - job-template:
1407     name: "{project-name}-pypi-stage-{stream}"
1408     id: gerrit-pypi-stage
1409     <<: *lf_pypi_common
1410     <<: *lf_pypi_publish_builders
1411
1412     cron: ""
1413     pypi-repo: pypi-test
1414
1415     gerrit_stage_triggers:
1416       - comment-added-contains-event:
1417           comment-contains-value: '^Patch Set\s+\d+:\s+stage-release\s*$'
1418
1419     scm:
1420       - lf-infra-gerrit-scm:
1421           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1422           git-url: "{git-url}"
1423           refspec: "$GERRIT_REFSPEC"
1424           branch: "$GERRIT_BRANCH"
1425           submodule-recursive: "{submodule-recursive}"
1426           submodule-timeout: "{submodule-timeout}"
1427           submodule-disable: "{submodule-disable}"
1428           # stage jobs always build from tip
1429           choosing-strategy: default
1430
1431     triggers:
1432       - timed: "{obj:cron}"
1433       - gerrit:
1434           server-name: "{gerrit-server-name}"
1435           trigger-on: "{obj:gerrit_stage_triggers}"
1436           projects:
1437             - project-compare-type: ANT
1438               project-pattern: "{project}"
1439               branches:
1440                 - branch-compare-type: ANT
1441                   branch-pattern: "**/{branch}"
1442               file-paths: "{obj:gerrit_trigger_file_paths}"
1443
1444 - job-template:
1445     name: "{project-name}-pypi-stage-{stream}"
1446     id: github-pypi-stage
1447     <<: *lf_pypi_common
1448     <<: *lf_pypi_publish_builders
1449
1450     cron: ""
1451     pypi-repo: pypi-test
1452
1453     properties:
1454       - github:
1455           url: "{github-url}/{github-org}/{project}"
1456
1457     scm:
1458       - lf-infra-github-scm:
1459           url: "{git-clone-url}{github-org}/{project}"
1460           refspec: ""
1461           branch: "refs/heads/{branch}"
1462           submodule-recursive: "{submodule-recursive}"
1463           submodule-timeout: "{submodule-timeout}"
1464           submodule-disable: "{submodule-disable}"
1465           choosing-strategy: default
1466           jenkins-ssh-credential: "{jenkins-ssh-credential}"
1467
1468     triggers:
1469       - timed: "{obj:cron}"
1470       - github-pull-request:
1471           trigger-phrase: "^stage-release$"
1472           only-trigger-phrase: true
1473           status-context: "Release"
1474           permit-all: true
1475           github-hooks: true
1476           white-list-target-branches:
1477             - "{branch}"
1478           included-regions: "{obj:github_included_regions}"