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