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