1167ca4ea6185c72d2c87ecc161c2fab1af3ed34
[releng/global-jjb.git] / lf-macros.yaml
1 ---
2 ############
3 # BUILDERS #
4 ############
5
6 - builder:
7     name: lf-fetch-dependent-patches
8     builders:
9       - shell: !include-raw: ../shell/gerrit-fetch-dependencies.sh
10       - inject:
11           properties-file: $WORKSPACE/.dependency.properties
12
13 - builder:
14     name: lf-infra-create-netrc
15     builders:
16       - inject:
17           properties-content: 'SERVER_ID={server-id}'
18       - shell: !include-raw-escape: ../shell/create-netrc.sh
19
20 - builder:
21     name: lf-infra-docker-login
22     builders:
23       - lf-provide-maven-settings:
24           global-settings-file: '{global-settings-file}'
25           settings-file: '{settings-file}'
26       - shell: !include-raw-escape: ../shell/docker-login.sh
27       - lf-provide-maven-settings-cleanup
28
29 - builder:
30     name: lf-infra-gpg-verify-git-signature
31     # TODO: Verify signature after downloading users public key from a locally
32     # created repository instead of the public keymesh. This requires a process
33     # in place to get ODL developers public keys into a local repository without
34     # increasing the job thoughput.
35     builders:
36       - shell: !include-raw: ../shell/gpg-verify-git-signature.sh
37
38 - builder:
39     name: lf-infra-ship-logs
40     builders:
41       - config-file-provider:
42           files:
43             - file-id: 'jenkins-log-archives-settings'
44               variable: 'SETTINGS_FILE'
45       - lf-infra-create-netrc:
46           server-id: logs
47       - shell: !include-raw:
48           - ../shell/lftools-install.sh
49           - ../shell/logs-deploy.sh
50       - shell: !include-raw:
51           - ../shell/logs-clear-credentials.sh
52       - description-setter:
53           regexp: '^Build logs: .*'
54
55 - builder:
56     name: lf-infra-packer-build
57     builders:
58       - config-file-provider:
59           files:
60             - file-id: '{packer-cloud-settings}'
61               variable: CLOUDENV
62       - inject:
63           properties-content: |
64               PACKER_PLATFORM={platform}
65               PACKER_TEMPLATE={template}
66               PACKER_VERSION={packer-version}
67       - shell: !include-raw-escape:
68           - ../shell/packer-install.sh
69           - ../shell/packer-build.sh
70       - shell: !include-raw:
71           - ../shell/packer-clear-credentials.sh
72
73 - builder:
74     name: lf-infra-packer-validate
75     builders:
76       - config-file-provider:
77           files:
78             - file-id: '{packer-cloud-settings}'
79               variable: 'CLOUDENV'
80       - inject:
81           properties-content: |
82               PACKER_VERSION={packer-version}
83       - shell: !include-raw-escape:
84           - ../shell/packer-install.sh
85           - ../shell/packer-validate.sh
86       - shell: !include-raw:
87           - ../shell/packer-clear-credentials.sh
88
89 - builder:
90     name: lf-infra-sysstat
91     builders:
92       - shell: !include-raw:
93           - ../shell/sysstat.sh
94
95 - builder:
96     name: lf-jacoco-nojava-workaround
97     builders:
98       - shell: 'mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes'
99
100 - builder:
101     name: lf-infra-deploy-maven-file
102     builders:
103       - lf-maven-install:
104           mvn-version: '{mvn-version}'
105       - lf-provide-maven-settings:
106           global-settings-file: '{global-settings-file}'
107           settings-file: '{settings-file}'
108       - inject:
109           properties-content: |
110               MAVEN_REPO_URL={maven-repo-url}
111               REPO_ID={repo-id}
112               GROUP_ID={group-id}
113               UPLOAD_FILES_PATH={upload-files-dir}
114       - shell: !include-raw-escape:
115           - ../shell/lftools-install.sh
116           - ../shell/common-variables.sh
117           - ../shell/deploy-maven-file.sh
118       - lf-provide-maven-settings-cleanup
119
120 - builder:
121     name: lf-maven-install
122     builders:
123       # Create a $HOME/.wgetrc to make the Maven download quiet.
124       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
125       - maven-target:
126           maven-version: '{mvn-version}'
127           goals: '--version'
128       - shell: 'rm "$HOME/.wgetrc"'
129
130 - builder:
131     name: lf-provide-maven-settings
132     builders:
133       - config-file-provider:
134           files:
135             - file-id: '{global-settings-file}'
136               variable: 'GLOBAL_SETTINGS_FILE'
137             - file-id: '{settings-file}'
138               variable: 'SETTINGS_FILE'
139
140 - builder:
141     name: lf-pip-install
142     builders:
143       - inject:
144           properties-content: PIP_PACKAGES={pip-packages}
145       - shell: !include-raw-escape: ../shell/pip-install.sh
146
147 - builder:
148     name: lf-provide-maven-settings-cleanup
149     builders:
150       - shell: |
151           #!/bin/bash
152           set +e  # DO NOT cause build failure if any of the rm calls fail.
153
154           rm "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
155
156           # In some cases we use the lf-provide-maven-settings macro to produce
157           # a "$HOME/.netrc" file containing credentials. Remove that file here
158           # too if it exists.
159           rm "$HOME/.netrc"
160
161           # DO NOT fail build if any of the above lines fail.
162           exit 0
163
164 - builder:
165     name: lf-rtd-trigger-build
166     builders:
167       - inject:
168           properties-content: RTD_PROJECT={rtd-project}
169       - shell: !include-raw-escape: ../shell/rtd-trigger-build.sh
170
171 - builder:
172     name: lf-rtd-verify
173     builders:
174       - inject:
175           properties-content: DOC_DIR={doc-dir}
176       - shell: !include-raw-escape:
177           - ../shell/tox-install.sh
178           - ../shell/rtd-verify.sh
179
180 ##############
181 # PARAMETERS #
182 ##############
183
184 - parameter:
185     name: lf-infra-maven-parameters
186     parameters:
187       - string:
188           name: M2_HOME
189           # Sets an env var for shell scripts to be able to call the dynamically
190           # installed maven without having to calculate the M2_HOME themselves.
191           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}'
192           description: 'Maven selector to be used by shell scripts'
193       - string:
194           name: MAVEN_OPTS
195           default: '{mvn-opts}'
196           description: |
197               Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
198       - string:
199           name: MAVEN_PARAMS
200           default: '{mvn-params}'
201           description: |
202               Maven parameters to pass to the mvn command.
203       - string:
204           name: MVN
205           # Sets an env var for shell scripts to be able to call the dynamically
206           # installed maven without having to calculate the path themselves.
207           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn'
208           description: 'Maven selector to be used by shell scripts'
209       - string:
210           name: STAGING_PROFILE_ID
211           default: '{staging-profile-id}'
212           description: |
213               Nexus staging profile ID.
214
215
216 - parameter:
217     name: lf-infra-openstack-parameters
218     parameters:
219       - string:
220           name: OS_CLOUD
221           default: '{os-cloud}'
222           description: |
223               The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
224               variable name that is significant to openstack client as a
225               environment variable. Please refer to the documentation for
226               further details.
227               https://docs.openstack.org/developer/python-openstackclient/
228
229
230 - parameter:
231     name: lf-infra-parameters
232     # Standard parameters used in the LF CI environments. Gerrit variables are
233     # not used by GitHub projects, but defining them isn't harmful.
234     parameters:
235       - string:
236           name: PROJECT
237           default: '{project}'
238           description: |
239               Parameter to identify a Gerrit project. This is typically the
240               project repo path as exists in Gerrit.
241               For example: ofextensions/circuitsw
242       - string:
243           name: STREAM
244           default: '{stream}'
245           description: |
246               Stream is often set to the same name as 'branch' but can
247               sometimes be used as a name representing a project's release code
248               name.
249       - string:
250           name: GERRIT_PROJECT
251           default: '{project}'
252           description: |
253               Parameter to identify Gerrit project. This is typically the
254               project repo path as exists in Gerrit.
255               For example: ofextensions/circuitsw
256
257               Note that Gerrit will override this parameter automatically if a
258               job is triggered by Gerrit.
259       - string:
260           name: GERRIT_BRANCH
261           default: '{branch}'
262           description: |
263               Parameter to identify a Gerrit branch.
264
265               Note that Gerrit will override this parameter automatically if a
266               job is triggered by Gerrit.
267       - string:
268           name: GERRIT_REFSPEC
269           default: 'refs/heads/{branch}'
270           description: |
271               Parameter to identify a refspec when pulling from Gerrit.
272
273               Note that Gerrit will override this parameter automatically if a
274               job is triggered by Gerrit.
275       - string:
276           name: LFTOOLS_VERSION
277           default: '{lftools-version}'
278           description: |
279               Version of lftools to install. Can be a specific version like
280               '0.6.0' or a PEP-440 definition.
281               https://www.python.org/dev/peps/pep-0440/
282               For example '<1.0.0' or '>=1.0.0,<2.0.0'.
283
284 - parameter:
285     name: lf-infra-node-parameters
286     parameters:
287       - string:
288           name: NODE_DIR
289           default: '{node-dir}'
290           description: Path to a Node project directory.
291       - string:
292           name: NODE_VERSION
293           default: '{node-version}'
294           description: Version of NodeJS to install.
295
296 - parameter:
297     name: lf-infra-tox-parameters
298     parameters:
299       - string:
300           name: TOX_DIR
301           default: '{tox-dir}'
302           description: |
303               Path to directory containing tox.ini file.
304       - string:
305           name: TOX_ENVS
306           default: '{tox-envs}'
307           description: |
308               Tox environments to run build against.
309               Example: docs,py2,py3
310
311 ##############
312 # PROPERTIES #
313 ##############
314
315 - property:
316     name: lf-infra-properties
317     properties:
318       - build-discarder:
319           # Allow build data to be stored at a length configured by the
320           # downstream project.
321           days-to-keep: '{build-days-to-keep}'
322           # Do not allow artifacts to be stored in Jenkins.
323           artifact-num-to-keep: 0
324
325 ##############
326 # PUBLISHERS #
327 ##############
328
329 - publisher:
330     name: lf-jacoco-report
331     publishers:
332       - jacoco:
333           exec-pattern: "**/**.exec"
334           class-pattern: "**/classes"
335           source-pattern: "**/src/main/java"
336           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
337           status-update: true
338           targets:
339             - branch:
340                 healthy: 10
341                 unhealthy: 20
342             - method:
343                 healthy: 50
344                 unhealthy: 40
345
346 - publisher:
347     name: lf-infra-publish
348     # lf-infra macro to finish up a build.
349     #
350     # Handles the following:
351     #   - Shipping logs to Nexus logs site repository
352     #   - Cleanup workspace
353     publishers:
354       - postbuildscript:
355           builders:
356             - lf-infra-sysstat
357             - lf-infra-ship-logs
358           script-only-if-succeeded: false
359           script-only-if-failed: false
360           mark-unstable-if-failed: false
361       - workspace-cleanup:
362           exclude:
363             # Do not clean up *.jenkins-trigger files for jobs that use a
364             # properties file as input for triggering another build.
365             - '**/*.jenkins-trigger'
366           fail-build: false
367
368 #######
369 # SCM #
370 #######
371
372 - scm:
373     name: lf-infra-gerrit-scm
374     scm:
375       - git:
376           credentials-id: '{jenkins-ssh-credential}'
377           url: '{git-url}'
378           refspec: '{refspec}'
379           branches:
380             - 'refs/heads/{branch}'
381           skip-tag: true
382           wipe-workspace: true
383           submodule:
384             recursive: '{submodule-recursive}'
385           choosing-strategy: '{choosing-strategy}'
386
387 - scm:
388     name: lf-infra-github-scm
389     scm:
390       - git:
391           credentials-id: '{jenkins-ssh-credential}'
392           url: '{url}'
393           refspec: '{refspec}'
394           branches:
395             - '{branch}'
396           skip-tag: true
397           wipe-workspace: true
398           submodule:
399             recursive: '{submodule-recursive}'
400           choosing-strategy: '{choosing-strategy}'
401
402 ############
403 # TRIGGERS #
404 ############
405
406 - trigger:
407     name: lf-infra-github-pr-trigger
408     triggers:
409       - github-pull-request:
410           trigger-phrase: '{trigger-phrase}'
411           only-trigger-phrase: '{only-trigger-phrase}'
412           status-context: '{status-context}'
413           permit-all: '{permit-all}'
414           github-hooks: '{github-hooks}'
415           auto-close-on-fail: false
416           org-list:
417             - '{github-org}'
418           white-list: '{obj:github_pr_whitelist}'
419           admin-list: '{obj:github_pr_admin_list}'
420
421 ############
422 # WRAPPERS #
423 ############
424
425 - wrapper:
426     name: lf-infra-wrappers
427     wrappers:
428       - mask-passwords
429       - timeout:
430           type: absolute
431           timeout: '{build-timeout}'
432           timeout-var: 'BUILD_TIMEOUT'
433           fail: true
434       - timestamps
435       - ssh-agent-credentials:
436           users:
437             - '{jenkins-ssh-credential}'
438       - openstack:
439           single-use: true
440       - config-file-provider:
441           files:
442             - file-id: npmrc
443               target: '$HOME/.npmrc'