Merge "Migrate node-verify job to global-jjb"
[releng/global-jjb.git] / jjb / lf-macros.yaml
1 ---
2 ############
3 # BUILDERS #
4 ############
5
6 - builder:
7     name: lf-infra-create-netrc
8     # Macro to create a ~/.netrc file from a Maven settings.xml
9     # Parameters:
10     #     {server-id} The id of a server as defined in settings.xml
11     builders:
12       - inject:
13           properties-content: 'SERVER_ID={server-id}'
14       - shell: !include-raw-escape: ../shell/create-netrc.sh
15
16 - builder:
17     name: lf-infra-docker-login
18     # Login into a custom hosted docker registry and / or docker.io
19     #
20     # The Jenkins system should have the following global variables defined
21     #
22     # DOCKER_REGISTRY : Optional
23     #                   The DNS address of the registry (IP or FQDN)
24     #                   ex: nexus3.example.com
25     #
26     # REGISTRY_PORTS  : Required if DOCKER_REGISTRY is set
27     #                   Space separated listing of the registry ports to login
28     #                   to
29     #                   ex: 10001 10002 10003 10004
30     #
31     # DOCKERHUB_EMAIL : Optional
32     #                   If this variable is set then an attempt to login to
33     #                   DockerHub (docker.io) will be also made. It should be
34     #                   set to the email address for the credentials that will
35     #                   get looked up. Only _one_ credential will ever be found
36     #                   in the maven settings file for DockerHub
37     builders:
38       - lf-provide-maven-settings:
39           global-settings-file: '{global-settings-file}'
40           settings-file: '{settings-file}'
41       - shell: !include-raw-escape: ../shell/docker-login.sh
42       - lf-provide-maven-settings-cleanup
43
44 - builder:
45     name: lf-infra-gpg-verify-git-signature
46     # Verify gpg signature of the latest commit message in $WORKSPACE
47     #
48     # This command assumes that $WORKSPACE is a git repo.
49     #
50     # TODO: Verify signature after downloading users public key from a locally
51     # created repository instead of the public keymesh. This requires a process
52     # in place to get ODL developers public keys into a local repository without
53     # increasing the job thoughput.
54     builders:
55       - shell: !include-raw: ../shell/gpg-verify-git-signature.sh
56
57 - builder:
58     name: lf-infra-ship-logs
59     builders:
60       - config-file-provider:
61           files:
62             - file-id: 'jenkins-log-archives-settings'
63               variable: 'SETTINGS_FILE'
64       - lf-infra-create-netrc:
65           server-id: logs
66       - shell: !include-raw:
67           - ../shell/lftools-install.sh
68           - ../shell/logs-deploy.sh
69       - shell: !include-raw:
70           - ../shell/logs-clear-credentials.sh
71       - description-setter:
72           regexp: '^Build logs: .*'
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-sysstat
110     builders:
111       - shell: !include-raw:
112           - ../shell/sysstat.sh
113
114 - builder:
115     name: lf-jacoco-nojava-workaround
116     builders:
117       - shell: 'mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes'
118
119 - builder:
120     name: lf-infra-deploy-maven-file
121     # Deploy files to a repository.
122     #
123     # The builder requires passing the following parameters
124     # REPO_ID:           Repository ID
125     # GROUP_ID:          Group ID of the repository
126     # UPLOAD_FILES_PATH: Path to directory containing one or more files
127     builders:
128       - lf-maven-install:
129           mvn-version: '{mvn-version}'
130       - lf-provide-maven-settings:
131           global-settings-file: '{global-settings-file}'
132           settings-file: '{settings-file}'
133       - inject:
134           properties-content: |
135               MAVEN_REPO_URL={maven-repo-url}
136               REPO_ID={repo-id}
137               GROUP_ID={group-id}
138               UPLOAD_FILES_PATH={upload-files-dir}
139       - shell: !include-raw-escape:
140           - ../shell/lftools-install.sh
141           - ../shell/common-variables.sh
142           - ../shell/deploy-maven-file.sh
143       - lf-provide-maven-settings-cleanup
144
145 - builder:
146     name: lf-maven-install
147     # call maven-target builder with a goal of --version to force Jenkins to
148     # install the needed maven version
149     builders:
150       # Create a $HOME/.wgetrc to make the Maven download quiet.
151       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
152       - maven-target:
153           maven-version: '{mvn-version}'
154           goals: '--version'
155       - shell: 'rm "$HOME/.wgetrc"'
156
157 - builder:
158     name: lf-provide-maven-settings
159     # Push a global settings and user settings maven files
160     builders:
161       - config-file-provider:
162           files:
163             - file-id: '{global-settings-file}'
164               variable: 'GLOBAL_SETTINGS_FILE'
165             - file-id: '{settings-file}'
166               variable: 'SETTINGS_FILE'
167
168 - builder:
169     name: lf-pip-install
170     # Call pip install to install packages into a virtualenv
171     # The first package listed in PIP_PACKAGES is used as the virtualenv name.
172     builders:
173       - inject:
174           properties-content: PIP_PACKAGES={pip-packages}
175       - shell: !include-raw-escape: ../shell/pip-install.sh
176
177 - builder:
178     name: lf-provide-maven-settings-cleanup
179     # Clear maven settings files after we are done using them
180     builders:
181       - shell: |
182           #!/bin/bash
183           set +e  # DO NOT cause build failure if any of the rm calls fail.
184
185           rm "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
186
187           # In some cases we use the lf-provide-maven-settings macro to produce
188           # a "$HOME/.netrc" file containing credentials. Remove that file here
189           # too if it exists.
190           rm "$HOME/.netrc"
191
192           # DO NOT fail build if any of the above lines fail.
193           exit 0
194
195 - builder:
196     name: lf-rtd-trigger-build
197     builders:
198       - inject:
199           properties-content: RTD_PROJECT={rtd-project}
200       - shell: !include-raw-escape: ../shell/rtd-trigger-build.sh
201
202 - builder:
203     name: lf-rtd-verify
204     builders:
205       - inject:
206           properties-content: DOC_DIR={doc-dir}
207       - shell: !include-raw-escape:
208           - ../shell/tox-install.sh
209           - ../shell/rtd-verify.sh
210
211 ##############
212 # PARAMETERS #
213 ##############
214
215 - parameter:
216     name: lf-infra-maven-parameters
217     parameters:
218       - string:
219           name: MAVEN_OPTS
220           default: '{mvn-opts}'
221           description: |
222               Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
223       - string:
224           name: MAVEN_PARAMS
225           default: '{mvn-params}'
226           description: |
227               Maven parameters to pass to the mvn command.
228       - string:
229           name: MVN
230           # Sets an env var for shell scripts to be able to call the dynamically
231           # installed maven without having to calculate the path themselves.
232           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn'
233           description: 'Maven selector to be used by shell scripts'
234       - string:
235           name: STAGING_PROFILE_ID
236           default: '{staging-profile-id}'
237           description: |
238               Nexus staging profile ID.
239
240
241 - parameter:
242     name: lf-infra-openstack-parameters
243     parameters:
244       - string:
245           name: OS_CLOUD
246           default: '{os-cloud}'
247           description: |
248               The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
249               variable name that is significant to openstack client as a
250               environment variable. Please refer to the documentation for
251               further details.
252               https://docs.openstack.org/developer/python-openstackclient/
253
254
255 - parameter:
256     name: lf-infra-parameters
257     # Standard parameters used in the LF CI environments. Gerrit variables are
258     # not used by GitHub projects, but defining them isn't harmful.
259     parameters:
260       - string:
261           name: PROJECT
262           default: '{project}'
263           description: |
264               Parameter to identify a Gerrit project. This is typically the
265               project repo path as exists in Gerrit.
266               For example: ofextensions/circuitsw
267       - string:
268           name: STREAM
269           default: '{stream}'
270           description: |
271               Stream is often set to the same name as 'branch' but can
272               sometimes be used as a name representing a project's release code
273               name.
274       - string:
275           name: GERRIT_PROJECT
276           default: '{project}'
277           description: |
278               Parameter to identify Gerrit project. This is typically the
279               project repo path as exists in Gerrit.
280               For example: ofextensions/circuitsw
281
282               Note that Gerrit will override this parameter automatically if a
283               job is triggered by Gerrit.
284       - string:
285           name: GERRIT_BRANCH
286           default: '{branch}'
287           description: |
288               Parameter to identify a Gerrit branch.
289
290               Note that Gerrit will override this parameter automatically if a
291               job is triggered by Gerrit.
292       - string:
293           name: GERRIT_REFSPEC
294           default: 'refs/heads/{branch}'
295           description: |
296               Parameter to identify a refspec when pulling from Gerrit.
297
298               Note that Gerrit will override this parameter automatically if a
299               job is triggered by Gerrit.
300       - string:
301           name: LFTOOLS_VERSION
302           default: '{lftools-version}'
303           description: |
304               Version of lftools to install. Can be a specific version like
305               '0.6.0' or a PEP-440 definition.
306               https://www.python.org/dev/peps/pep-0440/
307               For example '<1.0.0' or '>=1.0.0,<2.0.0'.
308
309 - parameter:
310     name: lf-infra-node-parameters
311     # Parameters for NodeJS
312     parameters:
313       - string:
314           name: NODE_DIR
315           default: '{node-dir}'
316           description: Path to a Node project directory.
317       - string:
318           name: NODE_VERSION
319           default: '{node-version}'
320           description: Version of NodeJS to install.
321
322 - parameter:
323     name: lf-infra-tox-parameters
324     # Useful parameters when working with TOX
325     # https://tox.readthedocs.io/
326     parameters:
327       - string:
328           name: TOX_DIR
329           default: '{tox-dir}'
330           description: |
331               Path to directory containing tox.ini file.
332       - string:
333           name: TOX_ENVS
334           default: '{tox-envs}'
335           description: |
336               Tox environments to run build against.
337               Example: docs,py2,py3
338
339 ##############
340 # PROPERTIES #
341 ##############
342
343 - property:
344     name: lf-infra-properties
345     properties:
346       - build-discarder:
347           # Allow build data to be stored at a length configured by the
348           # downstream project.
349           days-to-keep: '{build-days-to-keep}'
350           # Do not allow artifacts to be stored in Jenkins.
351           artifact-num-to-keep: 0
352
353 ##############
354 # PUBLISHERS #
355 ##############
356
357 - publisher:
358     name: lf-jacoco-report
359     publishers:
360       - jacoco:
361           exec-pattern: "**/**.exec"
362           class-pattern: "**/classes"
363           source-pattern: "**/src/main/java"
364           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
365           status-update: true
366           targets:
367             - branch:
368                 healthy: 10
369                 unhealthy: 20
370             - method:
371                 healthy: 50
372                 unhealthy: 40
373
374 - publisher:
375     name: lf-infra-publish
376     # lf-infra macro to finish up a build.
377     #
378     # Handles the following:
379     #   - Shipping logs to Nexus logs site repository
380     #   - Cleanup workspace
381     publishers:
382       - postbuildscript:
383           builders:
384             - lf-infra-sysstat
385             - lf-infra-ship-logs
386           script-only-if-succeeded: false
387           script-only-if-failed: false
388           mark-unstable-if-failed: false
389       - workspace-cleanup:
390           exclude:
391             # Do not clean up *.jenkins-trigger files for jobs that use a
392             # properties file as input for triggering another build.
393             - '**/*.jenkins-trigger'
394           fail-build: false
395
396 #######
397 # SCM #
398 #######
399
400 - scm:
401     name: lf-infra-gerrit-scm
402     scm:
403       - git:
404           credentials-id: '{jenkins-ssh-credential}'
405           url: '{git-url}'
406           refspec: '{refspec}'
407           branches:
408             - 'refs/heads/{branch}'
409           skip-tag: true
410           wipe-workspace: true
411           submodule:
412             recursive: '{submodule-recursive}'
413           choosing-strategy: '{choosing-strategy}'
414
415 - scm:
416     name: lf-infra-github-scm
417     scm:
418       - git:
419           credentials-id: '{jenkins-ssh-credential}'
420           url: '{url}'
421           refspec: '{refspec}'
422           skip-tag: true
423           wipe-workspace: true
424           submodule:
425             recursive: '{submodule-recursive}'
426           choosing-strategy: '{choosing-strategy}'
427
428 ############
429 # TRIGGERS #
430 ############
431
432 - trigger:
433     name: lf-infra-github-pr-trigger
434     triggers:
435       - github-pull-request:
436           trigger-phrase: '{trigger-phrase}'
437           only-trigger-phrase: '{only-trigger-phrase}'
438           status-context: '{status-context}'
439           permit-all: '{permit-all}'
440           github-hooks: '{github-hooks}'
441           auto-close-on-fail: false
442           org-list:
443             - '{github-org}'
444           white-list: '{obj:github_pr_whitelist}'
445           admin-list: '{obj:github_pr_admin_list}'
446
447 ############
448 # WRAPPERS #
449 ############
450
451 - wrapper:
452     name: lf-infra-wrappers
453     wrappers:
454       - mask-passwords
455       - timeout:
456           type: absolute
457           timeout: '{build-timeout}'
458           timeout-var: 'BUILD_TIMEOUT'
459           fail: true
460       - timestamps
461       - ssh-agent-credentials:
462           users:
463             - '{jenkins-ssh-credential}'
464       - openstack:
465           single-use: true