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