Merge "Migrate Maven Verify job template"
[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-provide-maven-settings-cleanup
170     # Clear maven settings files after we are done using them
171     builders:
172       - shell: |
173           #!/bin/bash
174           set +e  # DO NOT cause build failure if any of the rm calls fail.
175
176           rm "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
177
178           # In some cases we use the lf-provide-maven-settings macro to produce
179           # a "$HOME/.netrc" file containing credentials. Remove that file here
180           # too if it exists.
181           rm "$HOME/.netrc"
182
183           # DO NOT fail build if any of the above lines fail.
184           exit 0
185
186 ##############
187 # PARAMETERS #
188 ##############
189
190 - parameter:
191     name: lf-infra-maven-parameters
192     parameters:
193       - string:
194           name: MAVEN_OPTS
195           default: '{mvn-opts}'
196           description: |
197               Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
198       - string:
199           name: MAVEN_PARAMS
200           default: '{mvn-params}'
201           description: |
202               Maven parameters to pass to the mvn command.
203       - string:
204           name: MVN
205           # Sets an env var for shell scripts to be able to call the dynamically
206           # installed maven without having to calculate the path themselves.
207           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn'
208           description: 'Maven selector to be used by shell scripts'
209       - string:
210           name: STAGING_PROFILE_ID
211           default: '{staging-profile-id}'
212           description: |
213               Nexus staging profile ID.
214
215
216 - parameter:
217     name: lf-infra-openstack-parameters
218     parameters:
219       - string:
220           name: OS_CLOUD
221           default: '{os-cloud}'
222           description: |
223               The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
224               variable name that is significant to openstack client as a
225               environment variable. Please refer to the documentation for
226               further details.
227               https://docs.openstack.org/developer/python-openstackclient/
228
229
230 - parameter:
231     name: lf-infra-parameters
232     # Standard parameters used in the LF CI environments. Gerrit variables are
233     # not used by GitHub projects, but defining them isn't harmful.
234     parameters:
235       - string:
236           name: PROJECT
237           default: '{project}'
238           description: |
239               Parameter to identify a Gerrit project. This is typically the
240               project repo path as exists in Gerrit.
241               For example: ofextensions/circuitsw
242       - string:
243           name: STREAM
244           default: '{stream}'
245           description: |
246               Stream is often set to the same name as 'branch' but can
247               sometimes be used as a name representing a project's release code
248               name.
249       - string:
250           name: GERRIT_PROJECT
251           default: '{project}'
252           description: |
253               Parameter to identify Gerrit project. This is typically the
254               project repo path as exists in Gerrit.
255               For example: ofextensions/circuitsw
256
257               Note that Gerrit will override this parameter automatically if a
258               job is triggered by Gerrit.
259       - string:
260           name: GERRIT_BRANCH
261           default: '{branch}'
262           description: |
263               Parameter to identify a Gerrit branch.
264
265               Note that Gerrit will override this parameter automatically if a
266               job is triggered by Gerrit.
267       - string:
268           name: GERRIT_REFSPEC
269           default: 'refs/heads/{branch}'
270           description: |
271               Parameter to identify a refspec when pulling from Gerrit.
272
273               Note that Gerrit will override this parameter automatically if a
274               job is triggered by Gerrit.
275       - string:
276           name: LFTOOLS_VERSION
277           default: '{lftools-version}'
278           description: |
279               Version of lftools to install. Can be a specific version like
280               '0.6.0' or a PEP-440 definition.
281               https://www.python.org/dev/peps/pep-0440/
282               For example '<1.0.0' or '>=1.0.0,<2.0.0'.
283
284 - parameter:
285     name: lf-infra-tox-parameters
286     # Useful parameters when working with TOX
287     # https://tox.readthedocs.io/
288     parameters:
289       - string:
290           name: TOX_DIR
291           default: '{tox-dir}'
292           description: |
293               Path to directory containing tox.ini file.
294       - string:
295           name: TOX_ENVS
296           default: '{tox-envs}'
297           description: |
298               Tox environments to run build against.
299               Example: docs,py2,py3
300
301 ##############
302 # PROPERTIES #
303 ##############
304
305 - property:
306     name: lf-infra-properties
307     properties:
308       - build-discarder:
309           # Allow build data to be stored at a length configured by the
310           # downstream project.
311           days-to-keep: '{build-days-to-keep}'
312           # Do not allow artifacts to be stored in Jenkins.
313           artifact-num-to-keep: 0
314
315 ##############
316 # PUBLISHERS #
317 ##############
318
319 - publisher:
320     name: lf-jacoco-report
321     publishers:
322       - jacoco:
323           exec-pattern: "**/**.exec"
324           class-pattern: "**/classes"
325           source-pattern: "**/src/main/java"
326           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
327           status-update: true
328           targets:
329             - branch:
330                 healthy: 10
331                 unhealthy: 20
332             - method:
333                 healthy: 50
334                 unhealthy: 40
335
336 - publisher:
337     name: lf-infra-publish
338     # lf-infra macro to finish up a build.
339     #
340     # Handles the following:
341     #   - Shipping logs to Nexus logs site repository
342     #   - Cleanup workspace
343     publishers:
344       - postbuildscript:
345           builders:
346             - lf-infra-sysstat
347             - lf-infra-ship-logs
348           script-only-if-succeeded: false
349           script-only-if-failed: false
350           mark-unstable-if-failed: false
351       - workspace-cleanup:
352           exclude:
353             # Do not clean up *.jenkins-trigger files for jobs that use a
354             # properties file as input for triggering another build.
355             - '**/*.jenkins-trigger'
356           fail-build: false
357
358 #######
359 # SCM #
360 #######
361
362 - scm:
363     name: lf-infra-gerrit-scm
364     scm:
365       - git:
366           credentials-id: '{jenkins-ssh-credential}'
367           url: '{git-url}'
368           refspec: '{refspec}'
369           branches:
370             - 'refs/heads/{branch}'
371           skip-tag: true
372           wipe-workspace: true
373           submodule:
374             recursive: '{submodule-recursive}'
375           choosing-strategy: '{choosing-strategy}'
376
377 - scm:
378     name: lf-infra-github-scm
379     scm:
380       - git:
381           credentials-id: '{jenkins-ssh-credential}'
382           url: '{url}'
383           refspec: '{refspec}'
384           skip-tag: true
385           wipe-workspace: true
386           submodule:
387             recursive: '{submodule-recursive}'
388           choosing-strategy: '{choosing-strategy}'
389
390 ############
391 # TRIGGERS #
392 ############
393
394 - trigger:
395     name: lf-infra-github-pr-trigger
396     triggers:
397       - github-pull-request:
398           trigger-phrase: '{trigger-phrase}'
399           only-trigger-phrase: '{only-trigger-phrase}'
400           status-context: '{status-context}'
401           permit-all: '{permit-all}'
402           github-hooks: '{github-hooks}'
403           auto-close-on-fail: false
404           org-list:
405             - '{github-org}'
406           white-list: '{obj:github_pr_whitelist}'
407           admin-list: '{obj:github_pr_admin_list}'
408
409 ############
410 # WRAPPERS #
411 ############
412
413 - wrapper:
414     name: lf-infra-wrappers
415     wrappers:
416       - mask-passwords
417       - timeout:
418           type: absolute
419           timeout: '{build-timeout}'
420           timeout-var: 'BUILD_TIMEOUT'
421           fail: true
422       - timestamps
423       - ssh-agent-credentials:
424           users:
425             - '{jenkins-ssh-credential}'
426       - openstack:
427           single-use: true