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