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