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