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