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