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