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