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-sysstat
76     builders:
77       - shell: !include-raw:
78           - ../shell/sysstat.sh
79
80 - builder:
81     name: lf-jacoco-nojava-workaround
82     builders:
83       - shell: 'mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes'
84
85 - builder:
86     name: lf-infra-deploy-maven-file
87     # Deploy files to a repository.
88     #
89     # The builder requires passing the following parameters
90     # REPO_ID:           Repository ID
91     # GROUP_ID:          Group ID of the repository
92     # UPLOAD_FILES_PATH: Path to directory containing one or more files
93     builders:
94       - lf-maven-install:
95           mvn-version: '{mvn-version}'
96       - lf-provide-maven-settings:
97           global-settings-file: '{global-settings-file}'
98           settings-file: '{settings-file}'
99       - inject:
100           properties-content: |
101               REPO_ID={repo-id}
102               GROUP_ID={group-id}
103               UPLOAD_FILES_PATH={files-dir}
104       - shell: !include-raw-escape:
105           - ../shell/lftools-install.sh
106           - ../shell/common-variables.sh
107           - ../shell/deploy-maven-file.sh
108       - lf-provide-maven-settings-cleanup
109
110 - builder:
111     name: lf-maven-install
112     # call maven-target builder with a goal of --version to force Jenkins to
113     # install the needed maven version
114     builders:
115       # Create a $HOME/.wgetrc to make the Maven download quiet.
116       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
117       - maven-target:
118           maven-version: '{mvn-version}'
119           goals: '--version'
120       - shell: 'rm "$HOME/.wgetrc"'
121
122 - builder:
123     name: lf-provide-maven-settings
124     # Push a global settings and user settings maven files
125     builders:
126       - config-file-provider:
127           files:
128             - file-id: '{global-settings-file}'
129               variable: 'GLOBAL_SETTINGS_FILE'
130             - file-id: '{settings-file}'
131               variable: 'SETTINGS_FILE'
132
133 - builder:
134     name: lf-provide-maven-settings-cleanup
135     # Clear maven settings files after we are done using them
136     builders:
137       - shell: |
138           #!/bin/bash
139           set +e  # DO NOT cause build failure if any of the rm calls fail.
140
141           rm "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
142
143           # In some cases we use the lf-provide-maven-settings macro to produce
144           # a "$HOME/.netrc" file containing credentials. Remove that file here
145           # too if it exists.
146           rm "$HOME/.netrc"
147
148           # DO NOT fail build if any of the above lines fail.
149           exit 0
150
151 ##############
152 # PARAMETERS #
153 ##############
154
155 - parameter:
156     name: lf-infra-parameters
157     # Standard parameters used in the LF CI environments. Gerrit variables are
158     # not used by GitHub projects, but defining them isn't harmful.
159     parameters:
160       - string:
161           name: PROJECT
162           default: '{project}'
163           description: |
164               Parameter to identify a Gerrit project. This is typically the
165               project repo path as exists in Gerrit.
166               For example: ofextensions/circuitsw
167       - string:
168           name: STREAM
169           default: '{stream}'
170           description: |
171               Stream is often set to the same name as 'branch' but can
172               sometimes be used as a name representing a project's release code
173               name.
174       - string:
175           name: GERRIT_PROJECT
176           default: '{project}'
177           description: |
178               Parameter to identify Gerrit project. This is typically the
179               project repo path as exists in Gerrit.
180               For example: ofextensions/circuitsw
181
182               Note that Gerrit will override this parameter automatically if a
183               job is triggered by Gerrit.
184       - string:
185           name: GERRIT_BRANCH
186           default: '{branch}'
187           description: |
188               Parameter to identify a Gerrit branch.
189
190               Note that Gerrit will override this parameter automatically if a
191               job is triggered by Gerrit.
192       - string:
193           name: GERRIT_REFSPEC
194           default: ''
195           description: |
196               Parameter to identify a refspec when pulling from Gerrit.
197
198               Note that Gerrit will override this parameter automatically if a
199               job is triggered by Gerrit.
200
201 - parameter:
202     name: lf-infra-maven-parameters
203     parameters:
204       - string:
205           name: MAVEN_OPTS
206           default: '{mvn-opts}'
207           description: |
208               Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
209       - string:
210           name: MAVEN_PARAMS
211           default: '{mvn-params}'
212           description: |
213               Maven parameters to pass to the mvn command.
214       - string:
215           name: MVN
216           # Sets an env var for shell scripts to be able to call the dynamically
217           # installed maven without having to calculate the path themselves.
218           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn'
219           description: 'Maven selector to be used by shell scripts'
220       - string:
221           name: STAGING_PROFILE_ID
222           default: '{staging-profile-id}'
223           description: |
224               Nexus staging profile ID.
225
226 - parameter:
227     name: lf-infra-tox-parameters
228     # Useful parameters when working with TOX
229     # https://tox.readthedocs.io/
230     parameters:
231       - string:
232           name: TOX_DIR
233           default: '{tox-dir}'
234           description: |
235               Path to directory containing tox.ini file.
236       - string:
237           name: TOX_ENVS
238           default: '{tox-envs}'
239           description: |
240               Tox environments to run build against.
241               Example: docs,py2,py3
242
243 ##############
244 # PROPERTIES #
245 ##############
246
247 - property:
248     name: lf-infra-properties
249     properties:
250       - build-discarder:
251           # Allow build data to be stored at a length configured by the
252           # downstream project.
253           days-to-keep: '{build-days-to-keep}'
254           # Do not allow artifacts to be stored in Jenkins.
255           artifact-num-to-keep: 0
256
257 ##############
258 # PUBLISHERS #
259 ##############
260
261 - publisher:
262     name: lf-infra-publish
263     # lf-infra macro to finish up a build.
264     #
265     # Handles the following:
266     #   - Shipping logs to Nexus logs site repository
267     #   - Cleanup workspace
268     publishers:
269       - postbuildscript:
270           builders:
271             - lf-infra-sysstat
272             - lf-infra-ship-logs
273           script-only-if-succeeded: false
274           script-only-if-failed: false
275           mark-unstable-if-failed: false
276       - workspace-cleanup:
277           exclude:
278             # Do not clean up *.jenkins-trigger files for jobs that use a
279             # properties file as input for triggering another build.
280             - '**/*.jenkins-trigger'
281           fail-build: false
282
283 #######
284 # SCM #
285 #######
286
287 - scm:
288     name: lf-infra-gerrit-scm
289     scm:
290       - git:
291           credentials-id: '{jenkins-ssh-credential}'
292           url: '{git-url}'
293           refspec: '{refspec}'
294           branches:
295             - 'refs/heads/{branch}'
296           skip-tag: true
297           wipe-workspace: true
298           submodule:
299             recursive: '{submodule-recursive}'
300           choosing-strategy: '{choosing-strategy}'
301
302 - scm:
303     name: lf-infra-github-scm
304     scm:
305       - git:
306           credentials-id: '{jenkins-ssh-credential}'
307           url: '{url}'
308           refspec: '{refspec}'
309           skip-tag: true
310           wipe-workspace: true
311           submodule:
312             recursive: '{submodule-recursive}'
313           choosing-strategy: '{choosing-strategy}'
314
315 ############
316 # TRIGGERS #
317 ############
318
319 - trigger:
320     name: lf-infra-github-pr-trigger
321     triggers:
322       - github-pull-request:
323           trigger-phrase: '{trigger-phrase}'
324           only-trigger-phrase: '{only-trigger-phrase}'
325           status-context: '{status-context}'
326           permit-all: '{permit-all}'
327           github-hooks: '{github-hooks}'
328           auto-close-on-fail: false
329           org-list:
330             - '{github-org}'
331           white-list: '{obj:github_pr_whitelist}'
332           admin-list: '{obj:github_pr_admin_list}'
333
334 ############
335 # WRAPPERS #
336 ############
337
338 - wrapper:
339     name: lf-infra-wrappers
340     wrappers:
341       - mask-passwords
342       - timeout:
343           type: absolute
344           timeout: '{build-timeout}'
345           timeout-var: 'BUILD_TIMEOUT'
346           fail: true
347       - timestamps
348       - ssh-agent-credentials:
349           users:
350             - '{jenkins-ssh-credential}'
351       - openstack:
352           single-use: true