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