Add comment-to-gerrit macro
[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: lf-sigul-sign-dir
268     # Requires that Jenkins be configured with SIGUL_BRIDGE_IP as a global
269     # Environment variable
270     builders:
271       - conditional-step:
272           condition-kind: boolean-expression
273           condition-expression: '{sign-artifacts}'
274           steps:
275             - config-file-provider:
276                 files:
277                   - file-id: sigul-config
278                     variable: SIGUL_CONFIG
279                   - file-id: sigul-password
280                     variable: SIGUL_PASSWORD
281                   - file-id: sigul-pki
282                     variable: SIGUL_PKI
283             - shell: !include-raw-escape: ../shell/sigul-configuration.sh
284             - shell: !include-raw-escape: ../shell/sigul-install.sh
285             - inject:
286                 properties-content: |
287                     SIGN_DIR={sign-dir}
288                     SIGN_MODE={sign-mode}
289             - shell: !include-raw-escape:
290                 - ../shell/sigul-sign-dir.sh
291             - shell: !include-raw-escape: ../shell/sigul-configuration-cleanup.sh
292
293 - builder:
294     name: lf-infra-provide-docker-cleanup
295     builders:
296       - shell: |
297           #!/bin/bash
298           set +e  # DO NOT cause build failure if docker rmi fails
299           docker rmi -f $(docker images -a -q)
300           exit 0
301
302
303 ##############
304 # PARAMETERS #
305 ##############
306
307 - parameter:
308     name: lf-clm-parameters
309     parameters:
310       - string:
311           name: NEXUS_IQ_STAGE
312           default: '{nexus-iq-stage}'
313           description: |
314               Stage the policy evaluation will be run against on the Nexus IQ Server.
315
316 - parameter:
317     name: lf-cmake-parameters
318     # Parameters useful in CMake builds.
319     parameters:
320       - string:
321           name: BUILD_DIR
322           default: '{build-dir}'
323           description: 'Directory to build the project in.'
324       - string:
325           name: CMAKE_OPTS
326           default: '{cmake-opts}'
327           description: |
328               Options to pass to CMAKE.
329               Example: -DCMAKE_INSTALL_PREFIX=$WORKSPACE/target/output
330       - string:
331           name: INSTALL_PREFIX
332           default: '{install-prefix}'
333           description: 'Install prefix for C/C++ builds. Example: /usr/local'
334       - string:
335           name: MAKE_OPTS
336           default: '{make-opts}'
337           description: 'Options to pass to make. Example: -j8'
338
339 - parameter:
340     name: lf-infra-maven-parameters
341     parameters:
342       - string:
343           name: M2_HOME
344           # Sets an env var for shell scripts to be able to call the dynamically
345           # installed maven without having to calculate the M2_HOME themselves.
346           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}'
347           description: 'Maven selector to be used by shell scripts'
348       - string:
349           name: MAVEN_OPTS
350           default: '{mvn-opts}'
351           description: |
352               Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
353       - string:
354           name: MAVEN_PARAMS
355           default: '{mvn-params}'
356           description: |
357               Maven parameters to pass to the mvn command.
358       - string:
359           name: MVN
360           # Sets an env var for shell scripts to be able to call the dynamically
361           # installed maven without having to calculate the path themselves.
362           # yamllint disable-line rule:line-length
363           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn'
364           description: 'Maven selector to be used by shell scripts'
365
366 - parameter:
367     name: lf-infra-openstack-parameters
368     parameters:
369       - string:
370           name: OS_CLOUD
371           default: '{os-cloud}'
372           description: |
373               The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
374               variable name that is significant to openstack client as a
375               environment variable. Please refer to the documentation for
376               further details.
377               https://docs.openstack.org/developer/python-openstackclient/
378
379
380 - parameter:
381     name: lf-infra-parameters
382     # Standard parameters used in the LF CI environments. Gerrit variables are
383     # not used by GitHub projects, but defining them isn't harmful.
384     parameters:
385       - string:
386           name: PROJECT
387           default: '{project}'
388           description: |
389               Parameter to identify a SCM project to build. This is typically
390               the project repo path. For example: ofextensions/circuitsw
391       - string:
392           name: STREAM
393           default: '{stream}'
394           description: |
395               Stream is often set to the same name as 'branch' but can
396               sometimes be used as a name representing a project's release code
397               name.
398       - string:
399           name: GERRIT_PROJECT
400           default: '{project}'
401           description: |
402               Gerrit Trigger provided parameter to identify Gerrit project that
403               triggered the build. This is typically the project repo path as
404               exists in Gerrit. For example: ofextensions/circuitsw
405
406               If using Gerrit, in a manual build this should match the PROJECT
407               parameter above.
408       - string:
409           name: GERRIT_BRANCH
410           default: '{branch}'
411           description: |
412               Gerrit Trigger provided parameter to identify a Gerrit branch.
413
414               If using Gerrit, in a manual build override with the branch to
415               build against.
416       - string:
417           name: GERRIT_REFSPEC
418           default: 'refs/heads/{branch}'
419           description: |
420               Gerrit Trigger provided parameter to identify a refspec to fetch
421               from Gerrit.
422
423               If using Gerrit, in a manual build override with a refspec.
424               https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
425               For example: 'refs/heads/master'
426       - string:
427           name: sha1
428           default: 'origin/{branch}'
429           description: |
430               GitHub PR Trigger provided parameter for specifying the commit
431               to checkout.
432
433               If using GitHub, in a manual build override with a branch path or
434               sha1 hash to a specific commit. For example: 'origin/master'
435
436 - parameter:
437     name: lf-infra-node-parameters
438     parameters:
439       - string:
440           name: NODE_DIR
441           default: '{node-dir}'
442           description: Path to a Node project directory.
443       - string:
444           name: NODE_VERSION
445           default: '{node-version}'
446           description: Version of NodeJS to install.
447
448 - parameter:
449     name: lf-infra-tox-parameters
450     parameters:
451       - string:
452           name: TOX_DIR
453           default: '{tox-dir}'
454           description: |
455               Path to directory containing tox.ini file.
456       - string:
457           name: TOX_ENVS
458           default: '{tox-envs}'
459           description: |
460               Tox environments to run build against.
461               Example: docs,py2,py3
462
463 ##############
464 # PROPERTIES #
465 ##############
466
467 - property:
468     name: lf-infra-properties
469     properties:
470       - build-discarder:
471           # Allow build data to be stored at a length configured by the
472           # downstream project.
473           days-to-keep: '{build-days-to-keep}'
474           # Do not allow artifacts to be stored in Jenkins.
475           artifact-num-to-keep: 0
476
477 ##############
478 # PUBLISHERS #
479 ##############
480
481 - publisher:
482     name: lf-jacoco-report
483     publishers:
484       - jacoco:
485           exec-pattern: "**/**.exec"
486           class-pattern: "**/classes"
487           source-pattern: "**/src/main/java"
488           # yamllint disable-line rule:line-length
489           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
490           status-update: true
491           targets:
492             - branch:
493                 healthy: 10
494                 unhealthy: 20
495             - method:
496                 healthy: 50
497                 unhealthy: 40
498
499 - publisher:
500     name: lf-infra-publish
501     # lf-infra macro to finish up a build.
502     #
503     # Handles the following:
504     #   - Shipping logs to Nexus logs site repository
505     #   - Cleanup workspace
506     publishers:
507       - postbuildscript:
508           builders:
509             - role: BOTH
510               build-on:
511                 - ABORTED
512                 - FAILURE
513                 - NOT_BUILT
514                 - SUCCESS
515                 - UNSTABLE
516               build-steps:
517                 - lf-infra-sysstat
518                 - lf-infra-package-listing
519                 - lf-infra-ship-logs
520           mark-unstable-if-failed: true
521       - workspace-cleanup:
522           exclude:
523             # Do not clean up *.jenkins-trigger files for jobs that use a
524             # properties file as input for triggering another build.
525             - '**/*.jenkins-trigger'
526           fail-build: false
527
528 - publisher:
529     name: lf-infra-publish-windows
530     # lf-infra macro to finish up a build.
531     #
532     # Handles the following:
533     #   - Shipping logs to Nexus logs site repository
534     #   - Cleanup workspace
535     publishers:
536       # TODO: RELENG-1228 Develop log shipping script for Windows systems
537       # - postbuildscript:
538       #     builders:
539       #       - role: BOTH
540       #         build-on:
541       #           - ABORTED
542       #           - FAILURE
543       #           - NOT_BUILT
544       #           - SUCCESS
545       #           - UNSTABLE
546       #         build-steps:
547       #           - lf-infra-ship-logs-windows
548       #     mark-unstable-if-failed: true
549       - workspace-cleanup:
550           exclude:
551             # Do not clean up *.jenkins-trigger files for jobs that use a
552             # properties file as input for triggering another build.
553             - '**/*.jenkins-trigger'
554           fail-build: 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}'