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