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