Merge "Add docker clean 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-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 Gerrit project. This is typically the
293               project repo path as exists in Gerrit.
294               For example: ofextensions/circuitsw
295       - string:
296           name: STREAM
297           default: '{stream}'
298           description: |
299               Stream is often set to the same name as 'branch' but can
300               sometimes be used as a name representing a project's release code
301               name.
302       - string:
303           name: GERRIT_PROJECT
304           default: '{project}'
305           description: |
306               Parameter to identify Gerrit project. This is typically the
307               project repo path as exists in Gerrit.
308               For example: ofextensions/circuitsw
309
310               Note that Gerrit will override this parameter automatically if a
311               job is triggered by Gerrit.
312       - string:
313           name: GERRIT_BRANCH
314           default: '{branch}'
315           description: |
316               Parameter to identify a Gerrit branch.
317
318               Note that Gerrit will override this parameter automatically if a
319               job is triggered by Gerrit.
320       - string:
321           name: GERRIT_REFSPEC
322           default: 'refs/heads/{branch}'
323           description: |
324               Parameter to identify a refspec when pulling from Gerrit.
325
326               Note that Gerrit will override this parameter automatically if a
327               job is triggered by Gerrit.
328       - string:
329           name: LFTOOLS_VERSION
330           default: '{lftools-version}'
331           description: |
332               Version of lftools to install. Can be a specific version like
333               '0.6.0' or a PEP-440 definition.
334               https://www.python.org/dev/peps/pep-0440/
335               For example '<1.0.0' or '>=1.0.0,<2.0.0'.
336
337 - parameter:
338     name: lf-infra-node-parameters
339     parameters:
340       - string:
341           name: NODE_DIR
342           default: '{node-dir}'
343           description: Path to a Node project directory.
344       - string:
345           name: NODE_VERSION
346           default: '{node-version}'
347           description: Version of NodeJS to install.
348
349 - parameter:
350     name: lf-infra-tox-parameters
351     parameters:
352       - string:
353           name: TOX_DIR
354           default: '{tox-dir}'
355           description: |
356               Path to directory containing tox.ini file.
357       - string:
358           name: TOX_ENVS
359           default: '{tox-envs}'
360           description: |
361               Tox environments to run build against.
362               Example: docs,py2,py3
363
364 ##############
365 # PROPERTIES #
366 ##############
367
368 - property:
369     name: lf-infra-properties
370     properties:
371       - build-discarder:
372           # Allow build data to be stored at a length configured by the
373           # downstream project.
374           days-to-keep: '{build-days-to-keep}'
375           # Do not allow artifacts to be stored in Jenkins.
376           artifact-num-to-keep: 0
377
378 ##############
379 # PUBLISHERS #
380 ##############
381
382 - publisher:
383     name: lf-jacoco-report
384     publishers:
385       - jacoco:
386           exec-pattern: "**/**.exec"
387           class-pattern: "**/classes"
388           source-pattern: "**/src/main/java"
389           # yamllint disable-line rule:line-length
390           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
391           status-update: true
392           targets:
393             - branch:
394                 healthy: 10
395                 unhealthy: 20
396             - method:
397                 healthy: 50
398                 unhealthy: 40
399
400 - publisher:
401     name: lf-infra-publish
402     # lf-infra macro to finish up a build.
403     #
404     # Handles the following:
405     #   - Shipping logs to Nexus logs site repository
406     #   - Cleanup workspace
407     publishers:
408       - postbuildscript:
409           builders:
410             - role: BOTH
411               build-on:
412                 - ABORTED
413                 - FAILURE
414                 - NOT_BUILT
415                 - SUCCESS
416                 - UNSTABLE
417               build-steps:
418                 - lf-infra-sysstat
419                 - lf-infra-ship-logs
420           mark-unstable-if-failed: true
421       - workspace-cleanup:
422           exclude:
423             # Do not clean up *.jenkins-trigger files for jobs that use a
424             # properties file as input for triggering another build.
425             - '**/*.jenkins-trigger'
426           fail-build: false
427
428 #######
429 # SCM #
430 #######
431
432 - scm:
433     name: lf-infra-gerrit-scm
434     scm:
435       - git:
436           credentials-id: '{jenkins-ssh-credential}'
437           url: '{git-url}'
438           refspec: '{refspec}'
439           branches:
440             - 'refs/heads/{branch}'
441           skip-tag: true
442           wipe-workspace: true
443           submodule:
444             recursive: '{submodule-recursive}'
445           choosing-strategy: '{choosing-strategy}'
446
447 - scm:
448     name: lf-infra-github-scm
449     scm:
450       - git:
451           credentials-id: '{jenkins-ssh-credential}'
452           url: '{url}'
453           refspec: '{refspec}'
454           branches:
455             - '{branch}'
456           skip-tag: true
457           wipe-workspace: true
458           submodule:
459             recursive: '{submodule-recursive}'
460           choosing-strategy: '{choosing-strategy}'
461
462 ############
463 # TRIGGERS #
464 ############
465
466 - trigger:
467     name: lf-infra-github-pr-trigger
468     triggers:
469       - github-pull-request:
470           trigger-phrase: '{trigger-phrase}'
471           only-trigger-phrase: '{only-trigger-phrase}'
472           status-context: '{status-context}'
473           permit-all: '{permit-all}'
474           github-hooks: '{github-hooks}'
475           auto-close-on-fail: false
476           org-list:
477             - '{github-org}'
478           white-list: '{obj:github_pr_whitelist}'
479           admin-list: '{obj:github_pr_admin_list}'
480
481 ############
482 # WRAPPERS #
483 ############
484
485 - wrapper:
486     name: lf-infra-wrappers
487     wrappers:
488       - mask-passwords
489       - timeout:
490           type: absolute
491           timeout: '{build-timeout}'
492           timeout-var: 'BUILD_TIMEOUT'
493           fail: true
494       - timestamps
495       - ssh-agent-credentials:
496           users:
497             - '{jenkins-ssh-credential}'
498       - openstack:
499           single-use: true
500       - config-file-provider:
501           files:
502             - file-id: npmrc
503               target: '$HOME/.npmrc'
504             - file-id: pipconf
505               target: '$HOME/.config/pip/pip.conf'