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