Merge "lf-ci-jobs: Add git-validate-jira-urls.sh"
[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:
42           - ../shell/docker-login.sh
43       - lf-provide-maven-settings-cleanup
44
45 - builder:
46     name: lf-infra-gpg-verify-git-signature
47     # Verify gpg signature of the latest commit message in $WORKSPACE
48     #
49     # This command assumes that $WORKSPACE is a git repo.
50     #
51     # TODO: Verify signature after downloading users public key from a locally
52     # created repository instead of the public keymesh. This requires a process
53     # in place to get ODL developers public keys into a local repository without
54     # increasing the job thoughput.
55     builders:
56       - shell: !include-raw: ../shell/gpg-verify-git-signature.sh
57
58 - builder:
59     name: lf-infra-ship-logs
60     builders:
61       - config-file-provider:
62           files:
63             - file-id: 'jenkins-log-archives-settings'
64               variable: 'SETTINGS_FILE'
65       - lf-infra-create-netrc:
66           server-id: logs
67       - shell: !include-raw:
68           - ../shell/lftools-install.sh
69           - ../shell/logs-deploy.sh
70       - shell: !include-raw:
71           - ../shell/logs-clear-credentials.sh
72       - description-setter:
73           regexp: '^Build logs: .*'
74
75 - builder:
76     name: lf-infra-sysstat
77     builders:
78       - shell: !include-raw:
79           - ../shell/sysstat.sh
80
81 - builder:
82     name: lf-jacoco-nojava-workaround
83     builders:
84       - shell: 'mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes'
85
86 - builder:
87     name: lf-maven-install
88     # call maven-target builder with a goal of --version to force Jenkins to
89     # install the needed maven version
90     builders:
91       # Create a $HOME/.wgetrc to make the Maven download quiet.
92       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
93       - maven-target:
94           maven-version: '{mvn-version}'
95           goals: '--version'
96       - shell: 'rm "$HOME/.wgetrc"'
97
98 - builder:
99     name: lf-provide-maven-settings
100     # Push a global settings and user settings maven files
101     builders:
102       - config-file-provider:
103           files:
104             - file-id: '{global-settings-file}'
105               variable: 'GLOBAL_SETTINGS_FILE'
106             - file-id: '{settings-file}'
107               variable: 'SETTINGS_FILE'
108 - builder:
109     name: lf-provide-maven-settings-cleanup
110     # Clear maven settings files after we are done using them
111     builders:
112       - shell: |
113           #!/bin/bash
114           set +e  # DO NOT cause build failure if any of the rm calls fail.
115
116           rm "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
117
118           # In some cases we use the lf-provide-maven-settings macro to produce
119           # a "$HOME/.netrc" file containing credentials. Remove that file here
120           # too if it exists.
121           rm "$HOME/.netrc"
122
123           # DO NOT fail build if any of the above lines fail.
124           exit 0
125
126 ##############
127 # PARAMETERS #
128 ##############
129
130 - parameter:
131     name: lf-infra-parameters
132     # Standard parameters used in the LF CI environments. Gerrit variables are
133     # not used by GitHub projects, but defining them isn't harmful.
134     parameters:
135       - string:
136           name: PROJECT
137           default: '{project}'
138           description: |
139               Parameter to identify a Gerrit project. This is typically the
140               project repo path as exists in Gerrit.
141               For example: ofextensions/circuitsw
142       - string:
143           name: GERRIT_PROJECT
144           default: '{project}'
145           description: |
146               Parameter to identify Gerrit project. This is typically the
147               project repo path as exists in Gerrit.
148               For example: ofextensions/circuitsw
149
150               Note that Gerrit will override this parameter automatically if a
151               job is triggered by Gerrit.
152       - string:
153           name: GERRIT_BRANCH
154           default: '{branch}'
155           description: |
156               Parameter to identify a Gerrit branch.
157
158               Note that Gerrit will override this parameter automatically if a
159               job is triggered by Gerrit.
160       - string:
161           name: GERRIT_REFSPEC
162           default: ''
163           description: |
164               Parameter to identify a refspec when pulling from Gerrit.
165
166               Note that Gerrit will override this parameter automatically if a
167               job is triggered by Gerrit.
168
169 - parameter:
170     name: lf-infra-maven-parameters
171     parameters:
172       - string:
173           name: MAVEN_OPTS
174           default: '{mvn-opts}'
175           description: |
176               Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
177       - string:
178           name: MAVEN_PARAMS
179           default: '{mvn-params}'
180           description: |
181               Maven parameters to pass to the mvn command.
182       - string:
183           name: MVN
184           # Sets an env var for shell scripts to be able to call the dynamically
185           # installed maven without having to calculate the path themselves.
186           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn'
187           description: 'Maven selector to be used by shell scripts'
188       - string:
189           name: STAGING_PROFILE_ID
190           default: '{staging-profile-id}'
191           description: |
192               Nexus staging profile ID.
193
194 - parameter:
195     name: lf-infra-tox-parameters
196     # Useful parameters when working with TOX
197     # https://tox.readthedocs.io/
198     parameters:
199       - string:
200           name: TOX_DIR
201           default: '{tox-dir}'
202           description: |
203               Path to directory containing tox.ini file.
204       - string:
205           name: TOX_ENVS
206           default: '{tox-envs}'
207           description: |
208               Tox environments to run build against.
209               Example: docs,py2,py3
210
211 ##############
212 # PROPERTIES #
213 ##############
214
215 - property:
216     name: lf-infra-properties
217     properties:
218       - build-discarder:
219           # Allow build data to be stored at a length configured by the
220           # downstream project.
221           days-to-keep: '{build-days-to-keep}'
222           # Do not allow artifacts to be stored in Jenkins.
223           artifact-num-to-keep: 0
224
225 ##############
226 # PUBLISHERS #
227 ##############
228
229 - publisher:
230     name: lf-infra-publish
231     # lf-infra macro to finish up a build.
232     #
233     # Handles the following:
234     #   - Shipping logs to Nexus logs site repository
235     #   - Cleanup workspace
236     publishers:
237       - postbuildscript:
238           builders:
239             - lf-infra-sysstat
240             - lf-infra-ship-logs
241           script-only-if-succeeded: false
242           script-only-if-failed: false
243           mark-unstable-if-failed: false
244       - workspace-cleanup:
245           exclude:
246             # Do not clean up *.jenkins-trigger files for jobs that use a
247             # properties file as input for triggering another build.
248             - '**/*.jenkins-trigger'
249           fail-build: false
250
251 #######
252 # SCM #
253 #######
254
255 - scm:
256     name: lf-infra-gerrit-scm
257     scm:
258       - git:
259           credentials-id: '{jenkins-ssh-credential}'
260           url: '{git-url}'
261           refspec: '{refspec}'
262           branches:
263             - 'refs/heads/{branch}'
264           skip-tag: true
265           wipe-workspace: true
266           submodule:
267             recursive: '{submodule-recursive}'
268           choosing-strategy: '{choosing-strategy}'
269
270 - scm:
271     name: lf-infra-github-scm
272     scm:
273       - git:
274           credentials-id: '{jenkins-ssh-credential}'
275           url: '{url}'
276           refspec: '{refspec}'
277           skip-tag: true
278           wipe-workspace: true
279           submodule:
280             recursive: '{submodule-recursive}'
281           choosing-strategy: '{choosing-strategy}'
282
283 ############
284 # WRAPPERS #
285 ############
286
287 - wrapper:
288     name: lf-infra-wrappers
289     wrappers:
290       - mask-passwords
291       - timeout:
292           type: absolute
293           timeout: '{build-timeout}'
294           timeout-var: 'BUILD_TIMEOUT'
295           fail: true
296       - timestamps
297       - ssh-agent-credentials:
298           users:
299             - '{jenkins-ssh-credential}'
300       - openstack:
301           single-use: true