87c80a0b69ef78c4bd1ff1a674a92f05fb04ab3f
[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: "^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-maven-install
228     builders:
229       # Create a $HOME/.wgetrc to make the Maven download quiet.
230       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
231       - maven-target:
232           maven-version: "{mvn-version}"
233           goals: "--version"
234       - shell: 'rm "$HOME/.wgetrc"'
235
236 - builder:
237     name: lf-provide-maven-settings
238     builders:
239       - config-file-provider:
240           files:
241             - file-id: "{global-settings-file}"
242               variable: "GLOBAL_SETTINGS_FILE"
243             - file-id: "{settings-file}"
244               variable: "SETTINGS_FILE"
245
246 - builder:
247     name: lf-provide-maven-settings-cleanup
248     builders:
249       - shell: |
250           #!/bin/bash
251           set +e  # DO NOT cause build failure if any of the rm calls fail.
252
253           rm -f "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
254
255           # In some cases we use the lf-provide-maven-settings macro to produce
256           # a "$HOME/.netrc" file containing credentials. Remove that file here
257           # too if it exists.
258           rm -f "$HOME/.netrc"
259
260           # DO NOT fail build if any of the above lines fail.
261           exit 0
262
263 - builder:
264     name: lf-rtd-trigger-build
265     builders:
266       - inject:
267           properties-content: |
268             RTD_BUILD_URL={rtd-build-url}
269             RTD_TOKEN={rtd-token}
270       - shell: !include-raw-escape: ../shell/rtd-trigger-build.sh
271
272 - builder:
273     name: lf-rtd-verify
274     builders:
275       - inject:
276           properties-content: |
277             DOC_DIR={doc-dir}
278             PYTHON={python-version}
279       - shell: !include-raw-escape: ../shell/tox-install.sh
280       - shell: !include-raw-escape: ../shell/rtd-verify.sh
281
282 - builder:
283     name: lf-rtdv3-build
284     builders:
285       - inject:
286           properties-content: |
287             DEFAULT_VERSION={default-version}
288       - shell: !include-raw-escape: ../shell/rtdv3.sh
289
290 - builder:
291     name: check-info-votes
292     builders:
293       - inject:
294           properties-content: JENKINS_SSH_CREDENTIAL={jenkins-ssh-credential}
295       - shell: !include-raw-escape: ../shell/check-info-votes.sh
296
297 - builder:
298     name: lf-release
299     builders:
300       - config-file-provider:
301           files:
302             - file-id: lftoolsini
303               target: "$HOME/.config/lftools/lftools.ini"
304       - shell: !include-raw: ../shell/release-job.sh
305
306 - builder:
307     name: lf-sigul-sign-dir
308     # Requires that Jenkins be configured with SIGUL_BRIDGE_IP as a global
309     # Environment variable
310     builders:
311       - conditional-step:
312           condition-kind: boolean-expression
313           condition-expression: "{sign-artifacts}"
314           steps:
315             - config-file-provider:
316                 files:
317                   - file-id: sigul-config
318                     variable: SIGUL_CONFIG
319                   - file-id: sigul-password
320                     variable: SIGUL_PASSWORD
321                   - file-id: sigul-pki
322                     variable: SIGUL_PKI
323             - shell: !include-raw-escape: ../shell/sigul-configuration.sh
324             - shell: !include-raw-escape: ../shell/sigul-install.sh
325             - inject:
326                 properties-content: |
327                   SIGN_DIR={sign-dir}
328                   SIGN_MODE={sign-mode}
329             - shell: !include-raw-escape:
330                 - ../shell/sigul-sign-dir.sh
331             - shell: !include-raw-escape: ../shell/sigul-configuration-cleanup.sh
332
333 - builder:
334     name: lf-infra-provide-docker-cleanup
335     builders:
336       - shell: |
337           #!/bin/bash
338           set +e  # DO NOT cause build failure if docker rmi fails
339           docker rmi -f $(docker images -a -q)
340           exit 0
341
342 - builder:
343     name: lf-infra-sonar
344     # Run a Sonar Jenkins Plugin
345     builders:
346       - sonar:
347           sonar-name: Sonar
348           scanner-name: SonarQubeScanner
349           task: "{sonar-task}"
350           project: "{sonar-project-file}"
351           properties: "{sonar-properties}"
352           java-opts: "{sonar-java-opts}"
353           additional-arguments: "{sonar-additional-args}"
354
355 - builder:
356     name: lf-infra-sonar-with-prescan
357     # Run a Sonar Jenkins Plugin
358     builders:
359       - lf-sonar-prescan # Must be defined by caller
360       - sonar:
361           sonar-name: Sonar
362           scanner-name: SonarQubeScanner
363           task: "{sonar-task}"
364           project: "{sonar-project-file}"
365           properties: "{sonar-properties}"
366           java-opts: "{sonar-java-opts}"
367           additional-arguments: "{sonar-additional-args}"
368
369 ##############
370 # PARAMETERS #
371 ##############
372
373 - parameter:
374     name: lf-clm-parameters
375     parameters:
376       - string:
377           name: NEXUS_IQ_STAGE
378           default: "{nexus-iq-stage}"
379           description: |
380             Stage the policy evaluation will be run against on the Nexus IQ Server.
381
382 - parameter:
383     name: lf-cmake-parameters
384     # Parameters useful in CMake builds.
385     parameters:
386       - string:
387           name: BUILD_DIR
388           default: "{build-dir}"
389           description: "Directory to build the project in."
390       - string:
391           name: CMAKE_OPTS
392           default: "{cmake-opts}"
393           description: |
394             Options to pass to CMAKE.
395             Example: -DCMAKE_INSTALL_PREFIX=$WORKSPACE/target/output
396       - string:
397           name: INSTALL_PREFIX
398           default: "{install-prefix}"
399           description: "Install prefix for C/C++ builds. Example: /usr/local"
400       - string:
401           name: MAKE_OPTS
402           default: "{make-opts}"
403           description: "Options to pass to make. Example: -j8"
404
405 - parameter:
406     name: lf-infra-maven-parameters
407     parameters:
408       - string:
409           name: M2_HOME
410           # Sets an env var for shell scripts to be able to call the dynamically
411           # installed maven without having to calculate the M2_HOME themselves.
412           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}"
413           description: "Maven selector to be used by shell scripts"
414       - string:
415           name: MAVEN_OPTS
416           default: "{mvn-opts}"
417           description: |
418             Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
419       - string:
420           name: MAVEN_PARAMS
421           default: "{mvn-params}"
422           description: |
423             Maven parameters to pass to the mvn command.
424       - string:
425           name: MVN
426           # Sets an env var for shell scripts to be able to call the dynamically
427           # installed maven without having to calculate the path themselves.
428           # yamllint disable-line rule:line-length
429           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn"
430           description: "Maven selector to be used by shell scripts"
431
432 - parameter:
433     name: lf-infra-openstack-parameters
434     parameters:
435       - string:
436           name: OS_CLOUD
437           default: "{os-cloud}"
438           description: |
439             The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
440             variable name that is significant to openstack client as a
441             environment variable. Please refer to the documentation for
442             further details.
443             https://docs.openstack.org/developer/python-openstackclient/
444
445 - parameter:
446     name: lf-infra-parameters
447     # Standard parameters used in the LF CI environments. Gerrit variables are
448     # not used by GitHub projects, but defining them isn't harmful.
449     parameters:
450       - string:
451           name: PROJECT
452           default: "{project}"
453           description: |
454             Parameter to identify a SCM project to build. This is typically
455             the project repo path. For example: ofextensions/circuitsw
456       - string:
457           name: STREAM
458           default: "{stream}"
459           description: |
460             Stream is often set to the same name as 'branch' but can
461             sometimes be used as a name representing a project's release code
462             name.
463       - string:
464           name: GERRIT_PROJECT
465           default: "{project}"
466           description: |
467             Gerrit Trigger provided parameter to identify Gerrit project that
468             triggered the build. This is typically the project repo path as
469             exists in Gerrit. For example: ofextensions/circuitsw
470
471             If using Gerrit, in a manual build this should match the PROJECT
472             parameter above.
473       - string:
474           name: GERRIT_BRANCH
475           default: "{branch}"
476           description: |
477             Gerrit Trigger provided parameter to identify a Gerrit branch.
478
479             If using Gerrit, in a manual build override with the branch to
480             build against.
481       - string:
482           name: GERRIT_REFSPEC
483           default: "refs/heads/{branch}"
484           description: |
485             Gerrit Trigger provided parameter to identify a refspec to fetch
486             from Gerrit.
487
488             If using Gerrit, in a manual build override with a refspec.
489             https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
490             For example: 'refs/heads/master'
491       - string:
492           name: sha1
493           default: "origin/{branch}"
494           description: |
495             GitHub PR Trigger provided parameter for specifying the commit
496             to checkout.
497
498             If using GitHub, in a manual build override with a branch path or
499             sha1 hash to a specific commit. For example: 'origin/master'
500
501 - parameter:
502     name: lf-infra-node-parameters
503     parameters:
504       - string:
505           name: NODE_DIR
506           default: "{node-dir}"
507           description: Path to a Node project directory.
508       - string:
509           name: NODE_VERSION
510           default: "{node-version}"
511           description: Version of NodeJS to install.
512
513 - parameter:
514     name: lf-infra-tox-parameters
515     parameters:
516       - string:
517           name: TOX_DIR
518           default: "{tox-dir}"
519           description: |
520             Path to directory containing tox.ini file.
521       - string:
522           name: TOX_ENVS
523           default: "{tox-envs}"
524           description: |
525             Tox environments to run build against.
526             Example: docs,py2,py3
527
528 - parameter:
529     name: lf-build-with-parameters-maven-release
530     parameters:
531       - string:
532           name: VERSION
533           default: ""
534           description: "Version to release, for example: 1.0.0"
535       - string:
536           name: GIT_TAG
537           default: ""
538           description: "Tag to push to git repo; optional, defaults to VERSION"
539       - string:
540           name: LOG_DIR
541           default: ""
542           description: "Log dir, for example: project-maven-stage-master/17/"
543       - choice:
544           name: DISTRIBUTION_TYPE
545           choices:
546             - None
547             - container
548             - maven
549           description: "Set to maven for build with parameters"
550       - bool:
551           name: USE_RELEASE_FILE
552           default: "{use-release-file}"
553           description: "Set to False for job built with parameters"
554
555 ##############
556 # PROPERTIES #
557 ##############
558
559 - property:
560     name: lf-infra-properties
561     properties:
562       - build-discarder:
563           # Allow build data to be stored at a length configured by the
564           # downstream project.
565           days-to-keep: "{build-days-to-keep}"
566           # Do not allow artifacts to be stored in Jenkins.
567           artifact-num-to-keep: 0
568
569 ##############
570 # PUBLISHERS #
571 ##############
572
573 - publisher:
574     name: lf-jacoco-report
575     publishers:
576       - jacoco:
577           exec-pattern: "**/**.exec"
578           class-pattern: "**/classes"
579           source-pattern: "**/src/main/java"
580           # yamllint disable-line rule:line-length
581           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
582           status-update: true
583           targets:
584             - branch:
585                 healthy: 10
586                 unhealthy: 20
587             - method:
588                 healthy: 50
589                 unhealthy: 40
590
591 - publisher:
592     name: lf-infra-publish
593     # lf-infra macro to finish up a build.
594     #
595     # Handles the following:
596     #   - Shipping logs to Nexus logs site repository
597     #   - Cleanup workspace
598     publishers:
599       - postbuildscript:
600           builders:
601             - role: BOTH
602               build-on:
603                 - ABORTED
604                 - FAILURE
605                 - NOT_BUILT
606                 - SUCCESS
607                 - UNSTABLE
608               build-steps:
609                 - lf-infra-sysstat
610                 - lf-infra-package-listing
611                 - lf-infra-ship-logs
612           mark-unstable-if-failed: true
613       - workspace-cleanup:
614           exclude:
615             # Do not clean up *.jenkins-trigger files for jobs that use a
616             # properties file as input for triggering another build.
617             - "**/*.jenkins-trigger"
618           fail-build: false
619
620 - publisher:
621     name: lf-infra-publish-windows
622     # lf-infra macro to finish up a build.
623     #
624     # Handles the following:
625     #   - Shipping logs to Nexus logs site repository
626     #   - Cleanup workspace
627     publishers:
628       # TODO: RELENG-1228 Develop log shipping script for Windows systems
629       # - postbuildscript:
630       #     builders:
631       #       - role: BOTH
632       #         build-on:
633       #           - ABORTED
634       #           - FAILURE
635       #           - NOT_BUILT
636       #           - SUCCESS
637       #           - UNSTABLE
638       #         build-steps:
639       #           - lf-infra-ship-logs-windows
640       #     mark-unstable-if-failed: true
641       - workspace-cleanup:
642           exclude:
643             # Do not clean up *.jenkins-trigger files for jobs that use a
644             # properties file as input for triggering another build.
645             - "**/*.jenkins-trigger"
646           fail-build: false
647
648 #######
649 # SCM #
650 #######
651
652 - scm:
653     name: lf-infra-gerrit-scm
654     scm:
655       - git:
656           credentials-id: "{jenkins-ssh-credential}"
657           url: "{git-url}"
658           refspec: "{refspec}"
659           branches:
660             - "refs/heads/{branch}"
661           skip-tag: true
662           wipe-workspace: true
663           submodule:
664             disable: "{submodule-disable}"
665             recursive: "{submodule-recursive}"
666             timeout: "{submodule-timeout}"
667           choosing-strategy: "{choosing-strategy}"
668
669 - scm:
670     name: lf-infra-github-scm
671     scm:
672       - git:
673           credentials-id: "{jenkins-ssh-credential}"
674           url: "{url}"
675           refspec: "{refspec}"
676           branches:
677             - "{branch}"
678           skip-tag: true
679           wipe-workspace: true
680           submodule:
681             disable: "{submodule-disable}"
682             recursive: "{submodule-recursive}"
683             timeout: "{submodule-timeout}"
684           choosing-strategy: "{choosing-strategy}"
685
686 ############
687 # WRAPPERS #
688 ############
689
690 - wrapper:
691     name: lf-infra-wrappers-common
692     wrappers:
693       - mask-passwords
694       - timeout:
695           type: absolute
696           timeout: "{build-timeout}"
697           timeout-var: "BUILD_TIMEOUT"
698           fail: true
699       - timestamps
700       - openstack:
701           single-use: true
702
703 - wrapper:
704     name: lf-infra-wrappers
705     wrappers:
706       - lf-infra-wrappers-common:
707           build-timeout: "{build-timeout}"
708       - config-file-provider:
709           files:
710             - file-id: npmrc
711               target: "$HOME/.npmrc"
712             - file-id: pipconf
713               target: "$HOME/.config/pip/pip.conf"
714       - ssh-agent-credentials:
715           users:
716             - "{jenkins-ssh-credential}"
717
718 - wrapper:
719     name: lf-infra-wrappers-windows
720     wrappers:
721       - lf-infra-wrappers-common:
722           build-timeout: "{build-timeout}"