RTD Allow projects to change their default-version
[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: lf-rtdv3-build
279     builders:
280       - inject:
281           properties-content: |
282             DEFAULT_VERSION={default-version}
283       - shell: !include-raw: ../shell/rtdv3.sh
284
285 - builder:
286     name: check-info-votes
287     builders:
288       - inject:
289           properties-content: JENKINS_SSH_CREDENTIAL={jenkins-ssh-credential}
290       - shell: !include-raw-escape: ../shell/check-info-votes.sh
291
292 - builder:
293     name: lf-release
294     builders:
295       - config-file-provider:
296           files:
297             - file-id: lftoolsini
298               target: "$HOME/.config/lftools/lftools.ini"
299       - shell: !include-raw: ../shell/release-job.sh
300
301 - builder:
302     name: lf-sigul-sign-dir
303     # Requires that Jenkins be configured with SIGUL_BRIDGE_IP as a global
304     # Environment variable
305     builders:
306       - conditional-step:
307           condition-kind: boolean-expression
308           condition-expression: "{sign-artifacts}"
309           steps:
310             - config-file-provider:
311                 files:
312                   - file-id: sigul-config
313                     variable: SIGUL_CONFIG
314                   - file-id: sigul-password
315                     variable: SIGUL_PASSWORD
316                   - file-id: sigul-pki
317                     variable: SIGUL_PKI
318             - shell: !include-raw-escape: ../shell/sigul-configuration.sh
319             - shell: !include-raw-escape: ../shell/sigul-install.sh
320             - inject:
321                 properties-content: |
322                   SIGN_DIR={sign-dir}
323                   SIGN_MODE={sign-mode}
324             - shell: !include-raw-escape:
325                 - ../shell/sigul-sign-dir.sh
326             - shell: !include-raw-escape: ../shell/sigul-configuration-cleanup.sh
327
328 - builder:
329     name: lf-infra-provide-docker-cleanup
330     builders:
331       - shell: |
332           #!/bin/bash
333           set +e  # DO NOT cause build failure if docker rmi fails
334           docker rmi -f $(docker images -a -q)
335           exit 0
336
337 - builder:
338     name: lf-infra-sonar
339     # Run a Sonar Jenkins Plugin
340     builders:
341       - sonar:
342           sonar-name: Sonar
343           scanner-name: SonarQubeScanner
344           task: "{sonar-task}"
345           project: "{sonar-project-file}"
346           properties: "{sonar-properties}"
347           java-opts: "{sonar-java-opts}"
348           additional-arguments: "{sonar-additional-args}"
349
350 - builder:
351     name: lf-infra-sonar-with-prescan
352     # Run a Sonar Jenkins Plugin
353     builders:
354       - lf-sonar-prescan # Must be defined by caller
355       - sonar:
356           sonar-name: Sonar
357           scanner-name: SonarQubeScanner
358           task: "{sonar-task}"
359           project: "{sonar-project-file}"
360           properties: "{sonar-properties}"
361           java-opts: "{sonar-java-opts}"
362           additional-arguments: "{sonar-additional-args}"
363
364 ##############
365 # PARAMETERS #
366 ##############
367
368 - parameter:
369     name: lf-clm-parameters
370     parameters:
371       - string:
372           name: NEXUS_IQ_STAGE
373           default: "{nexus-iq-stage}"
374           description: |
375             Stage the policy evaluation will be run against on the Nexus IQ Server.
376
377 - parameter:
378     name: lf-cmake-parameters
379     # Parameters useful in CMake builds.
380     parameters:
381       - string:
382           name: BUILD_DIR
383           default: "{build-dir}"
384           description: "Directory to build the project in."
385       - string:
386           name: CMAKE_OPTS
387           default: "{cmake-opts}"
388           description: |
389             Options to pass to CMAKE.
390             Example: -DCMAKE_INSTALL_PREFIX=$WORKSPACE/target/output
391       - string:
392           name: INSTALL_PREFIX
393           default: "{install-prefix}"
394           description: "Install prefix for C/C++ builds. Example: /usr/local"
395       - string:
396           name: MAKE_OPTS
397           default: "{make-opts}"
398           description: "Options to pass to make. Example: -j8"
399
400 - parameter:
401     name: lf-infra-maven-parameters
402     parameters:
403       - string:
404           name: M2_HOME
405           # Sets an env var for shell scripts to be able to call the dynamically
406           # installed maven without having to calculate the M2_HOME themselves.
407           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}"
408           description: "Maven selector to be used by shell scripts"
409       - string:
410           name: MAVEN_OPTS
411           default: "{mvn-opts}"
412           description: |
413             Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
414       - string:
415           name: MAVEN_PARAMS
416           default: "{mvn-params}"
417           description: |
418             Maven parameters to pass to the mvn command.
419       - string:
420           name: MVN
421           # Sets an env var for shell scripts to be able to call the dynamically
422           # installed maven without having to calculate the path themselves.
423           # yamllint disable-line rule:line-length
424           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn"
425           description: "Maven selector to be used by shell scripts"
426
427 - parameter:
428     name: lf-infra-openstack-parameters
429     parameters:
430       - string:
431           name: OS_CLOUD
432           default: "{os-cloud}"
433           description: |
434             The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
435             variable name that is significant to openstack client as a
436             environment variable. Please refer to the documentation for
437             further details.
438             https://docs.openstack.org/developer/python-openstackclient/
439
440 - parameter:
441     name: lf-infra-parameters
442     # Standard parameters used in the LF CI environments. Gerrit variables are
443     # not used by GitHub projects, but defining them isn't harmful.
444     parameters:
445       - string:
446           name: PROJECT
447           default: "{project}"
448           description: |
449             Parameter to identify a SCM project to build. This is typically
450             the project repo path. For example: ofextensions/circuitsw
451       - string:
452           name: STREAM
453           default: "{stream}"
454           description: |
455             Stream is often set to the same name as 'branch' but can
456             sometimes be used as a name representing a project's release code
457             name.
458       - string:
459           name: GERRIT_PROJECT
460           default: "{project}"
461           description: |
462             Gerrit Trigger provided parameter to identify Gerrit project that
463             triggered the build. This is typically the project repo path as
464             exists in Gerrit. For example: ofextensions/circuitsw
465
466             If using Gerrit, in a manual build this should match the PROJECT
467             parameter above.
468       - string:
469           name: GERRIT_BRANCH
470           default: "{branch}"
471           description: |
472             Gerrit Trigger provided parameter to identify a Gerrit branch.
473
474             If using Gerrit, in a manual build override with the branch to
475             build against.
476       - string:
477           name: GERRIT_REFSPEC
478           default: "refs/heads/{branch}"
479           description: |
480             Gerrit Trigger provided parameter to identify a refspec to fetch
481             from Gerrit.
482
483             If using Gerrit, in a manual build override with a refspec.
484             https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
485             For example: 'refs/heads/master'
486       - string:
487           name: sha1
488           default: "origin/{branch}"
489           description: |
490             GitHub PR Trigger provided parameter for specifying the commit
491             to checkout.
492
493             If using GitHub, in a manual build override with a branch path or
494             sha1 hash to a specific commit. For example: 'origin/master'
495
496 - parameter:
497     name: lf-infra-node-parameters
498     parameters:
499       - string:
500           name: NODE_DIR
501           default: "{node-dir}"
502           description: Path to a Node project directory.
503       - string:
504           name: NODE_VERSION
505           default: "{node-version}"
506           description: Version of NodeJS to install.
507
508 - parameter:
509     name: lf-infra-tox-parameters
510     parameters:
511       - string:
512           name: TOX_DIR
513           default: "{tox-dir}"
514           description: |
515             Path to directory containing tox.ini file.
516       - string:
517           name: TOX_ENVS
518           default: "{tox-envs}"
519           description: |
520             Tox environments to run build against.
521             Example: docs,py2,py3
522
523 - parameter:
524     name: lf-build-with-parameters-maven-release
525     parameters:
526       - string:
527           name: VERSION
528           default: ""
529           description: "Version to release, for example: 1.0.0"
530       - string:
531           name: GIT_TAG
532           default: ""
533           description: "Tag to push to git repo; optional, defaults to VERSION"
534       - string:
535           name: LOG_DIR
536           default: ""
537           description: "Log dir, for example: project-maven-stage-master/17/"
538       - choice:
539           name: DISTRIBUTION_TYPE
540           choices:
541             - None
542             - container
543             - maven
544           description: "Set to maven for build with parameters"
545       - bool:
546           name: USE_RELEASE_FILE
547           default: "{use-release-file}"
548           description: "Set to False for job built with parameters"
549
550 ##############
551 # PROPERTIES #
552 ##############
553
554 - property:
555     name: lf-infra-properties
556     properties:
557       - build-discarder:
558           # Allow build data to be stored at a length configured by the
559           # downstream project.
560           days-to-keep: "{build-days-to-keep}"
561           # Do not allow artifacts to be stored in Jenkins.
562           artifact-num-to-keep: 0
563
564 ##############
565 # PUBLISHERS #
566 ##############
567
568 - publisher:
569     name: lf-jacoco-report
570     publishers:
571       - jacoco:
572           exec-pattern: "**/**.exec"
573           class-pattern: "**/classes"
574           source-pattern: "**/src/main/java"
575           # yamllint disable-line rule:line-length
576           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
577           status-update: true
578           targets:
579             - branch:
580                 healthy: 10
581                 unhealthy: 20
582             - method:
583                 healthy: 50
584                 unhealthy: 40
585
586 - publisher:
587     name: lf-infra-publish
588     # lf-infra macro to finish up a build.
589     #
590     # Handles the following:
591     #   - Shipping logs to Nexus logs site repository
592     #   - Cleanup workspace
593     publishers:
594       - postbuildscript:
595           builders:
596             - role: BOTH
597               build-on:
598                 - ABORTED
599                 - FAILURE
600                 - NOT_BUILT
601                 - SUCCESS
602                 - UNSTABLE
603               build-steps:
604                 - lf-infra-sysstat
605                 - lf-infra-package-listing
606                 - lf-infra-ship-logs
607           mark-unstable-if-failed: true
608       - workspace-cleanup:
609           exclude:
610             # Do not clean up *.jenkins-trigger files for jobs that use a
611             # properties file as input for triggering another build.
612             - "**/*.jenkins-trigger"
613           fail-build: false
614
615 - publisher:
616     name: lf-infra-publish-windows
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       # TODO: RELENG-1228 Develop log shipping script for Windows systems
624       # - postbuildscript:
625       #     builders:
626       #       - role: BOTH
627       #         build-on:
628       #           - ABORTED
629       #           - FAILURE
630       #           - NOT_BUILT
631       #           - SUCCESS
632       #           - UNSTABLE
633       #         build-steps:
634       #           - lf-infra-ship-logs-windows
635       #     mark-unstable-if-failed: true
636       - workspace-cleanup:
637           exclude:
638             # Do not clean up *.jenkins-trigger files for jobs that use a
639             # properties file as input for triggering another build.
640             - "**/*.jenkins-trigger"
641           fail-build: false
642
643 #######
644 # SCM #
645 #######
646
647 - scm:
648     name: lf-infra-gerrit-scm
649     scm:
650       - git:
651           credentials-id: "{jenkins-ssh-credential}"
652           url: "{git-url}"
653           refspec: "{refspec}"
654           branches:
655             - "refs/heads/{branch}"
656           skip-tag: true
657           wipe-workspace: true
658           submodule:
659             disable: "{submodule-disable}"
660             recursive: "{submodule-recursive}"
661             timeout: "{submodule-timeout}"
662           choosing-strategy: "{choosing-strategy}"
663
664 - scm:
665     name: lf-infra-github-scm
666     scm:
667       - git:
668           credentials-id: "{jenkins-ssh-credential}"
669           url: "{url}"
670           refspec: "{refspec}"
671           branches:
672             - "{branch}"
673           skip-tag: true
674           wipe-workspace: true
675           submodule:
676             disable: "{submodule-disable}"
677             recursive: "{submodule-recursive}"
678             timeout: "{submodule-timeout}"
679           choosing-strategy: "{choosing-strategy}"
680
681 ############
682 # WRAPPERS #
683 ############
684
685 - wrapper:
686     name: lf-infra-wrappers-common
687     wrappers:
688       - mask-passwords
689       - timeout:
690           type: absolute
691           timeout: "{build-timeout}"
692           timeout-var: "BUILD_TIMEOUT"
693           fail: true
694       - timestamps
695       - openstack:
696           single-use: true
697
698 - wrapper:
699     name: lf-infra-wrappers
700     wrappers:
701       - lf-infra-wrappers-common:
702           build-timeout: "{build-timeout}"
703       - config-file-provider:
704           files:
705             - file-id: npmrc
706               target: "$HOME/.npmrc"
707             - file-id: pipconf
708               target: "$HOME/.config/pip/pip.conf"
709       - ssh-agent-credentials:
710           users:
711             - "{jenkins-ssh-credential}"
712
713 - wrapper:
714     name: lf-infra-wrappers-windows
715     wrappers:
716       - lf-infra-wrappers-common:
717           build-timeout: "{build-timeout}"