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