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