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