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