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