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