0db15aa56a37c4b36b89c3e90a7b385598996c7a
[releng/global-jjb.git] / jjb / lf-macros.yaml
1 ---
2 ############
3 # BUILDERS #
4 ############
5
6 # To take advantage of this macro, have your build write
7 # out the file 'gerrit_comment.txt' with information to post
8 # back to gerrit and include this macro in the list of builders.
9 - builder:
10     name: comment-to-gerrit
11     builders:
12       - shell: !include-raw: ../shell/comment-to-gerrit.sh
13
14 - builder:
15     name: lf-fetch-dependent-patches
16     builders:
17       - shell: !include-raw: ../shell/gerrit-fetch-dependencies.sh
18       - inject:
19           properties-file: $WORKSPACE/.dependency.properties
20
21 - builder:
22     name: lf-license-check
23     builders:
24       - inject:
25           properties-content: |
26             FILE_PATTERNS={file-patterns}
27             SPDX_DISABLE={spdx-disable}
28             LHC_VERSION={lhc-version}
29             LICENSE_EXCLUDE_PATHS={license-exclude-paths}
30             LICENSES_ALLOWED={licenses-allowed}
31       - shell: !include-raw-escape:
32           - ../shell/license-check.sh
33
34 - builder:
35     name: lf-infra-create-netrc
36     builders:
37       - inject:
38           properties-content: "SERVER_ID={server-id}"
39       - shell: !include-raw-escape: ../shell/create-netrc.sh
40
41 - builder:
42     name: lf-infra-docker-login
43     builders:
44       - lf-provide-maven-settings:
45           global-settings-file: "{global-settings-file}"
46           settings-file: "{settings-file}"
47       - shell: !include-raw-escape: ../shell/docker-login.sh
48       - lf-provide-maven-settings-cleanup
49
50 - builder:
51     name: lf-infra-gpg-verify-git-signature
52     # TODO: Verify signature after downloading users public key from a locally
53     # created repository instead of the public keymesh. This requires a process
54     # in place to get ODL developers public keys into a local repository without
55     # increasing the job thoughput.
56     builders:
57       - shell: !include-raw: ../shell/gpg-verify-git-signature.sh
58
59 - builder:
60     name: lf-infra-pre-build
61     builders:
62       - shell: !include-raw-escape: ../shell/python-tools-install.sh
63
64 - builder:
65     name: lf-infra-ship-logs
66     builders:
67       # Ensure no pre-existing .netrc files are overriding logs config
68       - lf-provide-maven-settings-cleanup
69       - config-file-provider:
70           files:
71             - file-id: "jenkins-log-archives-settings"
72               variable: "SETTINGS_FILE"
73       - conditional-step:
74           condition-kind: regex-match
75           regex: "^.*logs-s3.*"
76           label: $S3_BUCKET
77           on-evaluation-failure: dont-run
78           steps:
79             - config-file-provider:
80                 files:
81                   - file-id: "jenkins-s3-log-ship"
82                     target: $HOME/.aws/credentials
83       - lf-infra-create-netrc:
84           server-id: logs
85       - shell: !include-raw:
86           # Ensure python-tools are installed in case job template does not
87           # call the lf-infra-pre-build macro.
88           - ../shell/python-tools-install.sh
89       - shell: !include-raw:
90           - ../shell/sudo-logs.sh
91       - shell: !include-raw:
92           - ../shell/job-cost.sh
93       - shell: !include-raw:
94           - ../shell/logs-deploy.sh
95       - shell: !include-raw:
96           - ../shell/logs-clear-credentials.sh
97       - description-setter:
98           regexp: "(^(Nexus|S3) build logs: .*)"
99
100 - builder:
101     name: lf-infra-package-listing
102     builders:
103       - shell: !include-raw:
104           - ../shell/package-listing.sh
105
106 - builder:
107     name: lf-infra-packer-build
108     builders:
109       - conditional-step:
110           condition-kind: boolean-expression
111           condition-expression: "{openstack}"
112           steps:
113             - config-file-provider:
114                 files:
115                   - file-id: clouds-yaml
116                     target: "$HOME/.config/openstack/clouds.yaml"
117             - inject:
118                 properties-content: OS_CLOUD={openstack-cloud}
119       - config-file-provider:
120           files:
121             - file-id: "{packer-cloud-settings}"
122               variable: CLOUDENV
123       - inject:
124           properties-content: |
125             PACKER_PLATFORM={platform}
126             PACKER_TEMPLATE={template}
127             PACKER_VERSION={packer-version}
128             UPDATE_CLOUD_IMAGE={update-cloud-image}
129       - shell: !include-raw-escape:
130           - ../shell/packer-install.sh
131           - ../shell/packer-build.sh
132       - shell: !include-raw:
133           - ../shell/packer-clear-credentials.sh
134
135 - builder:
136     name: lf-infra-packer-validate
137     builders:
138       - conditional-step:
139           condition-kind: boolean-expression
140           condition-expression: "{openstack}"
141           steps:
142             - config-file-provider:
143                 files:
144                   - file-id: clouds-yaml
145                     target: "$HOME/.config/openstack/clouds.yaml"
146             - inject:
147                 properties-content: OS_CLOUD={openstack-cloud}
148       - config-file-provider:
149           files:
150             - file-id: "{packer-cloud-settings}"
151               variable: CLOUDENV
152       - inject:
153           properties-content: |
154             PACKER_VERSION={packer-version}
155       - shell: !include-raw-escape:
156           - ../shell/packer-install.sh
157           - ../shell/packer-validate.sh
158       - shell: !include-raw:
159           - ../shell/packer-clear-credentials.sh
160
161 - builder:
162     name: lf-infra-update-packer-images
163     builders:
164       - shell: !include-raw: ../shell/update-cloud-images.sh
165
166 - builder:
167     name: lf-infra-push-gerrit-patch
168     builders:
169       - inject:
170           properties-content: |
171             PROJECT={project}
172             GERRIT_COMMIT_MESSAGE={gerrit-commit-message}
173             GERRIT_HOST={gerrit-host}
174             GERRIT_TOPIC={gerrit-topic}
175             GERRIT_USER={gerrit-user}
176             REVIEWERS_EMAIL={reviewers-email}
177       - shell: !include-raw-escape: ../shell/gerrit-push-patch.sh
178
179 - builder:
180     name: lf-infra-sysstat
181     builders:
182       - shell: !include-raw:
183           - ../shell/sysstat.sh
184
185 - builder:
186     name: lf-jacoco-nojava-workaround
187     builders:
188       - shell: "mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes"
189
190 - builder:
191     name: lf-infra-deploy-maven-file
192     builders:
193       - lf-maven-install:
194           mvn-version: "{mvn-version}"
195       - lf-provide-maven-settings:
196           global-settings-file: "{global-settings-file}"
197           settings-file: "{settings-file}"
198       - inject:
199           properties-content: |
200             MAVEN_REPO_URL={maven-repo-url}
201             REPO_ID={repo-id}
202             GROUP_ID={group-id}
203             UPLOAD_FILES_PATH={upload-files-dir}
204       - shell: !include-raw-escape:
205           - ../shell/common-variables.sh
206           - ../shell/deploy-maven-file.sh
207       - lf-provide-maven-settings-cleanup
208
209 - builder:
210     name: lf-maven-central
211     builders:
212       - conditional-step:
213           condition-kind: boolean-expression
214           condition-expression: "{mvn-central}"
215           steps:
216             - lf-provide-maven-settings:
217                 global-settings-file: "{mvn-global-settings}"
218                 settings-file: "{mvn-settings}"
219             - lf-infra-create-netrc:
220                 server-id: "ossrh"
221             - inject:
222                 properties-content: "OSSRH_PROFILE_ID={ossrh-profile-id}"
223             - shell: !include-raw-escape: ../shell/maven-central.sh
224             - lf-provide-maven-settings-cleanup
225
226 - builder:
227     name: lf-packagecloud-file-provider
228     builders:
229       - config-file-provider:
230           files:
231             - file-id: ".packagecloud"
232               target: "$HOME/.packagecloud"
233       - config-file-provider:
234           files:
235             - file-id: "packagecloud_api"
236               target: "$HOME/packagecloud_api"
237
238 - builder:
239     name: lf-packagecloud-push
240     builders:
241       - inject:
242           properties-content: |
243             BUILD_DIR={build-dir}
244             PACKAGECLOUD_ACCOUNT={packagecloud-account}
245             PACKAGECLOUD_REPO={packagecloud-repo}
246             DEBIAN_DISTRIBUTION_VERSIONS={debian-distribution-versions}
247             RPM_DISTRIBUTION_VERSIONS={rpm-distribution-versions}
248       - shell: !include-raw-escape: ../shell/packagecloud-push.sh
249
250 - builder:
251     name: lf-maven-install
252     builders:
253       # Create a $HOME/.wgetrc to make the Maven download quiet.
254       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
255       - maven-target:
256           maven-version: "{mvn-version}"
257           goals: "--version"
258       - shell: 'rm "$HOME/.wgetrc"'
259
260 - builder:
261     name: lf-provide-maven-settings
262     builders:
263       - config-file-provider:
264           files:
265             - file-id: "{global-settings-file}"
266               variable: "GLOBAL_SETTINGS_FILE"
267             - file-id: "{settings-file}"
268               variable: "SETTINGS_FILE"
269
270 - builder:
271     name: lf-provide-maven-settings-cleanup
272     builders:
273       - shell: |
274           #!/bin/bash
275           set +e  # DO NOT cause build failure if any of the rm calls fail.
276
277           rm -f "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
278
279           # In some cases we use the lf-provide-maven-settings macro to produce
280           # a "$HOME/.netrc" file containing credentials. Remove that file here
281           # too if it exists.
282           rm -f "$HOME/.netrc"
283
284           # DO NOT fail build if any of the above lines fail.
285           exit 0
286
287 - builder:
288     name: lf-rtd-trigger-build
289     builders:
290       - inject:
291           properties-content: |
292             RTD_BUILD_URL={rtd-build-url}
293             RTD_TOKEN={rtd-token}
294       - shell: !include-raw-escape: ../shell/rtd-trigger-build.sh
295
296 - builder:
297     name: lf-rtd-verify
298     builders:
299       - inject:
300           properties-content: |
301             DOC_DIR={doc-dir}
302             PYTHON={python-version}
303       - shell: !include-raw-escape: ../shell/tox-install.sh
304       - shell: !include-raw-escape: ../shell/rtd-verify.sh
305
306 - builder:
307     name: lf-rtdv3-build
308     builders:
309       - inject:
310           properties-content: |
311             DEFAULT_VERSION={default-version}
312       - shell: !include-raw-escape: ../shell/rtdv3.sh
313
314 - builder:
315     name: check-info-votes
316     builders:
317       - inject:
318           properties-content: JENKINS_SSH_CREDENTIAL={jenkins-ssh-credential}
319       - shell: !include-raw-escape: ../shell/check-info-votes.sh
320
321 - builder:
322     name: lf-release
323     builders:
324       - config-file-provider:
325           files:
326             - file-id: lftoolsini
327               target: "$HOME/.config/lftools/lftools.ini"
328       - shell: !include-raw: ../shell/release-job.sh
329
330 - builder:
331     name: lf-sigul-sign-dir
332     # Requires that Jenkins be configured with SIGUL_BRIDGE_IP as a global
333     # Environment variable
334     builders:
335       - conditional-step:
336           condition-kind: boolean-expression
337           condition-expression: "{sign-artifacts}"
338           steps:
339             - config-file-provider:
340                 files:
341                   - file-id: sigul-config
342                     variable: SIGUL_CONFIG
343                   - file-id: sigul-password
344                     variable: SIGUL_PASSWORD
345                   - file-id: sigul-pki
346                     variable: SIGUL_PKI
347             - shell: !include-raw-escape: ../shell/sigul-configuration.sh
348             - shell: !include-raw-escape: ../shell/sigul-install.sh
349             - inject:
350                 properties-content: |
351                   SIGN_DIR={sign-dir}
352                   SIGN_MODE={sign-mode}
353             - shell: !include-raw-escape:
354                 - ../shell/sigul-sign-dir.sh
355             - shell: !include-raw-escape: ../shell/sigul-configuration-cleanup.sh
356
357 - builder:
358     name: lf-infra-provide-docker-cleanup
359     builders:
360       - shell: |
361           #!/bin/bash
362           set +e  # DO NOT cause build failure if docker rmi fails
363           docker rmi -f $(docker images -a -q)
364           exit 0
365
366 - builder:
367     name: lf-infra-sonar
368     # Run a Sonar Jenkins Plugin
369     builders:
370       - sonar:
371           sonar-name: Sonar
372           scanner-name: SonarQubeScanner
373           task: "{sonar-task}"
374           project: "{sonar-project-file}"
375           properties: "{sonar-properties}"
376           java-opts: "{sonar-java-opts}"
377           additional-arguments: "{sonar-additional-args}"
378
379 - builder:
380     name: lf-infra-sonar-with-prescan
381     # Run a Sonar Jenkins Plugin
382     builders:
383       - lf-sonar-prescan # Must be defined by caller
384       - sonar:
385           sonar-name: Sonar
386           scanner-name: SonarQubeScanner
387           task: "{sonar-task}"
388           project: "{sonar-project-file}"
389           properties: "{sonar-properties}"
390           java-opts: "{sonar-java-opts}"
391           additional-arguments: "{sonar-additional-args}"
392
393 ##############
394 # PARAMETERS #
395 ##############
396
397 - parameter:
398     name: lf-autotools-parameters
399     # Parameters for configure-make builds.
400     parameters:
401       - string:
402           name: CONFIGURE_OPTS
403           default: "{configure-opts}"
404           description: |
405             Options to pass to configure.
406             Example: --build=i686-pc-linux-gnu
407       - string:
408           name: INSTALL_PREFIX
409           default: "{install-prefix}"
410           description: |
411             Install prefix for configure.
412             Usually a workspace subdirectory.
413       - string:
414           name: MAKE_OPTS
415           default: "{make-opts}"
416           description: |
417             Options to pass to make.
418             Example: -j8 all
419
420 - parameter:
421     name: lf-clm-parameters
422     parameters:
423       - string:
424           name: NEXUS_IQ_STAGE
425           default: "{nexus-iq-stage}"
426           description: |
427             Stage the policy evaluation will be run against on the Nexus IQ Server.
428
429 - parameter:
430     name: lf-cmake-parameters
431     # Parameters useful in CMake builds.
432     parameters:
433       - string:
434           name: BUILD_DIR
435           default: "{build-dir}"
436           description: "Directory to build the project in."
437       - string:
438           name: CMAKE_OPTS
439           default: "{cmake-opts}"
440           description: |
441             Options to pass to CMAKE.
442             Example: -DCMAKE_INSTALL_PREFIX=$WORKSPACE/target/output
443       - string:
444           name: INSTALL_PREFIX
445           default: "{install-prefix}"
446           description: "Install prefix for C/C++ builds. Example: /usr/local"
447       - string:
448           name: MAKE_OPTS
449           default: "{make-opts}"
450           description: "Options to pass to make. Example: -j8"
451
452 - parameter:
453     name: lf-infra-maven-parameters
454     parameters:
455       - string:
456           name: M2_HOME
457           # Sets an env var for shell scripts to be able to call the dynamically
458           # installed maven without having to calculate the M2_HOME themselves.
459           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}"
460           description: "Maven selector to be used by shell scripts"
461       - string:
462           name: MAVEN_OPTS
463           default: "{mvn-opts}"
464           description: |
465             Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
466       - string:
467           name: MAVEN_PARAMS
468           default: "{mvn-params}"
469           description: |
470             Maven parameters to pass to the mvn command.
471       - string:
472           name: MVN
473           # Sets an env var for shell scripts to be able to call the dynamically
474           # installed maven without having to calculate the path themselves.
475           # yamllint disable-line rule:line-length
476           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn"
477           description: "Maven selector to be used by shell scripts"
478
479 - parameter:
480     name: lf-infra-openstack-parameters
481     parameters:
482       - string:
483           name: OS_CLOUD
484           default: "{os-cloud}"
485           description: |
486             The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
487             variable name that is significant to openstack client as a
488             environment variable. Please refer to the documentation for
489             further details.
490             https://docs.openstack.org/developer/python-openstackclient/
491
492 - parameter:
493     name: lf-infra-parameters
494     # Standard parameters used in the LF CI environments. Gerrit variables are
495     # not used by GitHub projects, but defining them isn't harmful.
496     parameters:
497       - string:
498           name: PROJECT
499           default: "{project}"
500           description: |
501             Parameter to identify a SCM project to build. This is typically
502             the project repo path. For example: ofextensions/circuitsw
503       - string:
504           name: STREAM
505           default: "{stream}"
506           description: |
507             Stream is often set to the same name as 'branch' but can
508             sometimes be used as a name representing a project's release code
509             name.
510       - string:
511           name: GERRIT_PROJECT
512           default: "{project}"
513           description: |
514             Gerrit Trigger provided parameter to identify Gerrit project that
515             triggered the build. This is typically the project repo path as
516             exists in Gerrit. For example: ofextensions/circuitsw
517
518             If using Gerrit, in a manual build this should match the PROJECT
519             parameter above.
520       - string:
521           name: GERRIT_BRANCH
522           default: "{branch}"
523           description: |
524             Gerrit Trigger provided parameter to identify a Gerrit branch.
525
526             If using Gerrit, in a manual build override with the branch to
527             build against.
528       - string:
529           name: GERRIT_REFSPEC
530           default: "refs/heads/{branch}"
531           description: |
532             Gerrit Trigger provided parameter to identify a refspec to fetch
533             from Gerrit.
534
535             If using Gerrit, in a manual build override with a refspec.
536             https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
537             For example: 'refs/heads/master'
538       - string:
539           name: sha1
540           default: "origin/{branch}"
541           description: |
542             GitHub PR Trigger provided parameter for specifying the commit
543             to checkout.
544
545             If using GitHub, in a manual build override with a branch path or
546             sha1 hash to a specific commit. For example: 'origin/master'
547
548 - parameter:
549     name: lf-infra-node-parameters
550     parameters:
551       - string:
552           name: NODE_DIR
553           default: "{node-dir}"
554           description: Path to a Node project directory.
555       - string:
556           name: NODE_VERSION
557           default: "{node-version}"
558           description: Version of NodeJS to install.
559
560 - parameter:
561     name: lf-infra-tox-parameters
562     parameters:
563       - string:
564           name: TOX_DIR
565           default: "{tox-dir}"
566           description: |
567             Path to directory containing tox.ini file.
568       - string:
569           name: TOX_ENVS
570           default: "{tox-envs}"
571           description: |
572             Tox environments to run build against.
573             Example: docs,py2,py3
574
575 - parameter:
576     name: lf-build-with-parameters-maven-release
577     parameters:
578       - string:
579           name: VERSION
580           default: ""
581           description: "Version to release, for example: 1.0.0"
582       - string:
583           name: GIT_TAG
584           default: ""
585           description: "Tag to push to git repo; optional, defaults to VERSION"
586       - string:
587           name: LOG_DIR
588           default: ""
589           description: "Log dir, for example: project-maven-stage-master/17/"
590       - choice:
591           name: DISTRIBUTION_TYPE
592           choices:
593             - None
594             - container
595             - maven
596           description: "Set to maven for build with parameters"
597       - bool:
598           name: USE_RELEASE_FILE
599           default: "{use-release-file}"
600           description: "Set to False for job built with parameters"
601
602 ##############
603 # PROPERTIES #
604 ##############
605
606 - property:
607     name: lf-infra-properties
608     properties:
609       - build-discarder:
610           # Allow build data to be stored at a length configured by the
611           # downstream project.
612           days-to-keep: "{build-days-to-keep}"
613           # Do not allow artifacts to be stored in Jenkins.
614           artifact-num-to-keep: 0
615
616 ##############
617 # PUBLISHERS #
618 ##############
619
620 - publisher:
621     name: lf-jacoco-report
622     publishers:
623       - jacoco:
624           exec-pattern: "**/**.exec"
625           class-pattern: "**/classes"
626           source-pattern: "**/src/main/java"
627           # yamllint disable-line rule:line-length
628           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
629           status-update: true
630           targets:
631             - branch:
632                 healthy: 10
633                 unhealthy: 20
634             - method:
635                 healthy: 50
636                 unhealthy: 40
637
638 - publisher:
639     name: lf-infra-publish
640     # lf-infra macro to finish up a build.
641     #
642     # Handles the following:
643     #   - Shipping logs to Nexus logs site repository
644     #   - Cleanup workspace
645     publishers:
646       - postbuildscript:
647           builders:
648             - role: BOTH
649               build-on:
650                 - ABORTED
651                 - FAILURE
652                 - NOT_BUILT
653                 - SUCCESS
654                 - UNSTABLE
655               build-steps:
656                 - lf-infra-sysstat
657                 - lf-infra-package-listing
658                 - lf-infra-ship-logs
659           mark-unstable-if-failed: true
660       - workspace-cleanup:
661           exclude:
662             # Do not clean up *.jenkins-trigger files for jobs that use a
663             # properties file as input for triggering another build.
664             - "**/*.jenkins-trigger"
665           fail-build: false
666
667 - publisher:
668     name: lf-infra-publish-windows
669     # lf-infra macro to finish up a build.
670     #
671     # Handles the following:
672     #   - Shipping logs to Nexus logs site repository
673     #   - Cleanup workspace
674     publishers:
675       # TODO: RELENG-1228 Develop log shipping script for Windows systems
676       # - postbuildscript:
677       #     builders:
678       #       - role: BOTH
679       #         build-on:
680       #           - ABORTED
681       #           - FAILURE
682       #           - NOT_BUILT
683       #           - SUCCESS
684       #           - UNSTABLE
685       #         build-steps:
686       #           - lf-infra-ship-logs-windows
687       #     mark-unstable-if-failed: true
688       - workspace-cleanup:
689           exclude:
690             # Do not clean up *.jenkins-trigger files for jobs that use a
691             # properties file as input for triggering another build.
692             - "**/*.jenkins-trigger"
693           fail-build: false
694
695 #######
696 # SCM #
697 #######
698
699 - scm:
700     name: lf-infra-gerrit-scm
701     scm:
702       - git:
703           credentials-id: "{jenkins-ssh-credential}"
704           url: "{git-url}"
705           refspec: "{refspec}"
706           branches:
707             - "refs/heads/{branch}"
708           skip-tag: true
709           wipe-workspace: true
710           submodule:
711             disable: "{submodule-disable}"
712             recursive: "{submodule-recursive}"
713             timeout: "{submodule-timeout}"
714           choosing-strategy: "{choosing-strategy}"
715
716 - scm:
717     name: lf-infra-github-scm
718     scm:
719       - git:
720           credentials-id: "{jenkins-ssh-credential}"
721           url: "{url}"
722           refspec: "{refspec}"
723           branches:
724             - "{branch}"
725           skip-tag: true
726           wipe-workspace: true
727           submodule:
728             disable: "{submodule-disable}"
729             recursive: "{submodule-recursive}"
730             timeout: "{submodule-timeout}"
731           choosing-strategy: "{choosing-strategy}"
732
733 ############
734 # WRAPPERS #
735 ############
736
737 - wrapper:
738     name: lf-infra-wrappers-common
739     wrappers:
740       - mask-passwords
741       - timeout:
742           type: absolute
743           timeout: "{build-timeout}"
744           timeout-var: "BUILD_TIMEOUT"
745           fail: true
746       - timestamps
747       - openstack:
748           single-use: true
749
750 - wrapper:
751     name: lf-infra-wrappers
752     wrappers:
753       - lf-infra-wrappers-common:
754           build-timeout: "{build-timeout}"
755       - config-file-provider:
756           files:
757             - file-id: npmrc
758               target: "$HOME/.npmrc"
759             - file-id: pipconf
760               target: "$HOME/.config/pip/pip.conf"
761       - ssh-agent-credentials:
762           users:
763             - "{jenkins-ssh-credential}"
764
765 - wrapper:
766     name: lf-infra-wrappers-windows
767     wrappers:
768       - lf-infra-wrappers-common:
769           build-timeout: "{build-timeout}"