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