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