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