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