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