Add generic push changes to gerrit builder
[releng/global-jjb.git] / jjb / 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-push-gerrit-patch
91     builders:
92       - inject:
93           properties-content: |
94               PROJECT='{project}'
95               GERRIT_COMMIT_MESSAGE='{gerrit-commit-message}'
96               GERRIT_HOST='{gerrit-host}'
97               GERRIT_TOPIC='{gerrit-topic}'
98               GERRIT_USER='{gerrit-user}'
99               REVIEWERS_EMAIL='{reviewers-email}'
100       - shell: !include-raw-escape: ../shell/gerrit-push-patch.sh
101
102 - builder:
103     name: lf-infra-sysstat
104     builders:
105       - shell: !include-raw:
106           - ../shell/sysstat.sh
107
108 - builder:
109     name: lf-jacoco-nojava-workaround
110     builders:
111       - shell: 'mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes'
112
113 - builder:
114     name: lf-infra-deploy-maven-file
115     builders:
116       - lf-maven-install:
117           mvn-version: '{mvn-version}'
118       - lf-provide-maven-settings:
119           global-settings-file: '{global-settings-file}'
120           settings-file: '{settings-file}'
121       - inject:
122           properties-content: |
123               MAVEN_REPO_URL={maven-repo-url}
124               REPO_ID={repo-id}
125               GROUP_ID={group-id}
126               UPLOAD_FILES_PATH={upload-files-dir}
127       - shell: !include-raw-escape:
128           - ../shell/lftools-install.sh
129           - ../shell/common-variables.sh
130           - ../shell/deploy-maven-file.sh
131       - lf-provide-maven-settings-cleanup
132
133 - builder:
134     name: lf-maven-install
135     builders:
136       # Create a $HOME/.wgetrc to make the Maven download quiet.
137       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
138       - maven-target:
139           maven-version: '{mvn-version}'
140           goals: '--version'
141       - shell: 'rm "$HOME/.wgetrc"'
142
143 - builder:
144     name: lf-provide-maven-settings
145     builders:
146       - config-file-provider:
147           files:
148             - file-id: '{global-settings-file}'
149               variable: 'GLOBAL_SETTINGS_FILE'
150             - file-id: '{settings-file}'
151               variable: 'SETTINGS_FILE'
152
153 - builder:
154     name: lf-provide-sigul-configuration
155     # Push configuration files to interact with sigul
156     builders:
157       - config-file-provider:
158           files:
159             - file-id: sigul-config
160               variable: SIGUL_CONFIG
161             - file-id: sigul-password
162               variable: SIGUL_PASSWORD
163             - file-id: sigul-pki
164               variable: SIGUL_PKI
165       - shell: !include-raw-escape: ../shell/sigul-configuration.sh
166
167 - builder:
168     name: lf-pip-install
169     builders:
170       - inject:
171           properties-content: PIP_PACKAGES={pip-packages}
172       - shell: !include-raw-escape: ../shell/pip-install.sh
173
174 - builder:
175     name: lf-provide-maven-settings-cleanup
176     builders:
177       - shell: |
178           #!/bin/bash
179           set +e  # DO NOT cause build failure if any of the rm calls fail.
180
181           rm -f "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
182
183           # In some cases we use the lf-provide-maven-settings macro to produce
184           # a "$HOME/.netrc" file containing credentials. Remove that file here
185           # too if it exists.
186           rm -f "$HOME/.netrc"
187
188           # DO NOT fail build if any of the above lines fail.
189           exit 0
190
191 - builder:
192     name: lf-provide-sigul-configuration-cleanup
193     # Clear sigul configuration files after we're done using them
194     builders:
195       - shell: !include-raw-escape: ../shell/sigul-configuration-cleanup.sh
196
197 - builder:
198     name: lf-rtd-trigger-build
199     builders:
200       - inject:
201           properties-content: RTD_PROJECT={rtd-project}
202       - shell: !include-raw-escape: ../shell/rtd-trigger-build.sh
203
204 - builder:
205     name: lf-rtd-verify
206     builders:
207       - inject:
208           properties-content: DOC_DIR={doc-dir}
209       - shell: !include-raw-escape:
210           - ../shell/tox-install.sh
211           - ../shell/rtd-verify.sh
212
213 - builder:
214     name: lf-sigul-install
215     # Requires that Jenkins be configured with SIGUL_BRIDGE_IP as a global
216     # Environment variable
217     builder:
218       - shell: !include-raw-escape: ../shell/sigul-install.sh
219
220 ##############
221 # PARAMETERS #
222 ##############
223
224 - parameter:
225     name: lf-infra-maven-parameters
226     parameters:
227       - string:
228           name: M2_HOME
229           # Sets an env var for shell scripts to be able to call the dynamically
230           # installed maven without having to calculate the M2_HOME themselves.
231           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}'
232           description: 'Maven selector to be used by shell scripts'
233       - string:
234           name: MAVEN_OPTS
235           default: '{mvn-opts}'
236           description: |
237               Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
238       - string:
239           name: MAVEN_PARAMS
240           default: '{mvn-params}'
241           description: |
242               Maven parameters to pass to the mvn command.
243       - string:
244           name: MVN
245           # Sets an env var for shell scripts to be able to call the dynamically
246           # installed maven without having to calculate the path themselves.
247           # yamllint disable-line rule:line-length
248           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn'
249           description: 'Maven selector to be used by shell scripts'
250       - string:
251           name: STAGING_PROFILE_ID
252           default: '{staging-profile-id}'
253           description: |
254               Nexus staging profile ID.
255
256
257 - parameter:
258     name: lf-infra-openstack-parameters
259     parameters:
260       - string:
261           name: OS_CLOUD
262           default: '{os-cloud}'
263           description: |
264               The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
265               variable name that is significant to openstack client as a
266               environment variable. Please refer to the documentation for
267               further details.
268               https://docs.openstack.org/developer/python-openstackclient/
269
270
271 - parameter:
272     name: lf-infra-parameters
273     # Standard parameters used in the LF CI environments. Gerrit variables are
274     # not used by GitHub projects, but defining them isn't harmful.
275     parameters:
276       - string:
277           name: PROJECT
278           default: '{project}'
279           description: |
280               Parameter to identify a Gerrit project. This is typically the
281               project repo path as exists in Gerrit.
282               For example: ofextensions/circuitsw
283       - string:
284           name: STREAM
285           default: '{stream}'
286           description: |
287               Stream is often set to the same name as 'branch' but can
288               sometimes be used as a name representing a project's release code
289               name.
290       - string:
291           name: GERRIT_PROJECT
292           default: '{project}'
293           description: |
294               Parameter to identify Gerrit project. This is typically the
295               project repo path as exists in Gerrit.
296               For example: ofextensions/circuitsw
297
298               Note that Gerrit will override this parameter automatically if a
299               job is triggered by Gerrit.
300       - string:
301           name: GERRIT_BRANCH
302           default: '{branch}'
303           description: |
304               Parameter to identify a Gerrit branch.
305
306               Note that Gerrit will override this parameter automatically if a
307               job is triggered by Gerrit.
308       - string:
309           name: GERRIT_REFSPEC
310           default: 'refs/heads/{branch}'
311           description: |
312               Parameter to identify a refspec when pulling from Gerrit.
313
314               Note that Gerrit will override this parameter automatically if a
315               job is triggered by Gerrit.
316       - string:
317           name: LFTOOLS_VERSION
318           default: '{lftools-version}'
319           description: |
320               Version of lftools to install. Can be a specific version like
321               '0.6.0' or a PEP-440 definition.
322               https://www.python.org/dev/peps/pep-0440/
323               For example '<1.0.0' or '>=1.0.0,<2.0.0'.
324
325 - parameter:
326     name: lf-infra-node-parameters
327     parameters:
328       - string:
329           name: NODE_DIR
330           default: '{node-dir}'
331           description: Path to a Node project directory.
332       - string:
333           name: NODE_VERSION
334           default: '{node-version}'
335           description: Version of NodeJS to install.
336
337 - parameter:
338     name: lf-infra-tox-parameters
339     parameters:
340       - string:
341           name: TOX_DIR
342           default: '{tox-dir}'
343           description: |
344               Path to directory containing tox.ini file.
345       - string:
346           name: TOX_ENVS
347           default: '{tox-envs}'
348           description: |
349               Tox environments to run build against.
350               Example: docs,py2,py3
351
352 ##############
353 # PROPERTIES #
354 ##############
355
356 - property:
357     name: lf-infra-properties
358     properties:
359       - build-discarder:
360           # Allow build data to be stored at a length configured by the
361           # downstream project.
362           days-to-keep: '{build-days-to-keep}'
363           # Do not allow artifacts to be stored in Jenkins.
364           artifact-num-to-keep: 0
365
366 ##############
367 # PUBLISHERS #
368 ##############
369
370 - publisher:
371     name: lf-jacoco-report
372     publishers:
373       - jacoco:
374           exec-pattern: "**/**.exec"
375           class-pattern: "**/classes"
376           source-pattern: "**/src/main/java"
377           # yamllint disable-line rule:line-length
378           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
379           status-update: true
380           targets:
381             - branch:
382                 healthy: 10
383                 unhealthy: 20
384             - method:
385                 healthy: 50
386                 unhealthy: 40
387
388 - publisher:
389     name: lf-infra-publish
390     # lf-infra macro to finish up a build.
391     #
392     # Handles the following:
393     #   - Shipping logs to Nexus logs site repository
394     #   - Cleanup workspace
395     publishers:
396       - postbuildscript:
397           builders:
398             - role: BOTH
399               build-on:
400                 - ABORTED
401                 - FAILURE
402                 - NOT_BUILT
403                 - SUCCESS
404                 - UNSTABLE
405               build-steps:
406                 - lf-infra-sysstat
407                 - lf-infra-ship-logs
408           mark-unstable-if-failed: true
409       - workspace-cleanup:
410           exclude:
411             # Do not clean up *.jenkins-trigger files for jobs that use a
412             # properties file as input for triggering another build.
413             - '**/*.jenkins-trigger'
414           fail-build: false
415
416 #######
417 # SCM #
418 #######
419
420 - scm:
421     name: lf-infra-gerrit-scm
422     scm:
423       - git:
424           credentials-id: '{jenkins-ssh-credential}'
425           url: '{git-url}'
426           refspec: '{refspec}'
427           branches:
428             - 'refs/heads/{branch}'
429           skip-tag: true
430           wipe-workspace: true
431           submodule:
432             recursive: '{submodule-recursive}'
433           choosing-strategy: '{choosing-strategy}'
434
435 - scm:
436     name: lf-infra-github-scm
437     scm:
438       - git:
439           credentials-id: '{jenkins-ssh-credential}'
440           url: '{url}'
441           refspec: '{refspec}'
442           branches:
443             - '{branch}'
444           skip-tag: true
445           wipe-workspace: true
446           submodule:
447             recursive: '{submodule-recursive}'
448           choosing-strategy: '{choosing-strategy}'
449
450 ############
451 # TRIGGERS #
452 ############
453
454 - trigger:
455     name: lf-infra-github-pr-trigger
456     triggers:
457       - github-pull-request:
458           trigger-phrase: '{trigger-phrase}'
459           only-trigger-phrase: '{only-trigger-phrase}'
460           status-context: '{status-context}'
461           permit-all: '{permit-all}'
462           github-hooks: '{github-hooks}'
463           auto-close-on-fail: false
464           org-list:
465             - '{github-org}'
466           white-list: '{obj:github_pr_whitelist}'
467           admin-list: '{obj:github_pr_admin_list}'
468
469 ############
470 # WRAPPERS #
471 ############
472
473 - wrapper:
474     name: lf-infra-wrappers
475     wrappers:
476       - mask-passwords
477       - timeout:
478           type: absolute
479           timeout: '{build-timeout}'
480           timeout-var: 'BUILD_TIMEOUT'
481           fail: true
482       - timestamps
483       - ssh-agent-credentials:
484           users:
485             - '{jenkins-ssh-credential}'
486       - openstack:
487           single-use: true
488       - config-file-provider:
489           files:
490             - file-id: npmrc
491               target: '$HOME/.npmrc'
492             - file-id: pipconf
493               target: '$HOME/.config/pip/pip.conf'