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