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