48a688eec7a87b1dca6c62565ed6919bc9ff610e
[releng/global-jjb.git] / docs / jjb / lf-maven-jobs.rst
1 ##########
2 Maven Jobs
3 ##########
4
5 Job Groups
6 ==========
7
8 .. include:: ../job-groups.rst
9
10 Below is a list of Maven job groups:
11
12 .. literalinclude:: ../../jjb/lf-maven-job-groups.yaml
13    :language: yaml
14
15
16 Macros
17 ======
18
19 lf-infra-maven-sonar
20 --------------------
21
22 Runs Sonar against a Maven project.
23
24 :Required Parameters:
25
26     :java-version: Version of Java to execute Sonar with.
27     :mvn-version: Version of Maven to execute Sonar with.
28     :mvn-settings: Maven settings.xml file containing credentials to use.
29
30 lf-infra-maven-sonarcloud
31 -------------------------
32
33 Runs Sonar against a Maven project and pushes results to SonarCloud.
34
35 :Required Parameters:
36
37     :java-version: Version of Java to execute Sonar with.
38     :mvn-version: Version of Maven to execute Sonar with.
39     :mvn-settings: Maven settings.xml file containing credentials to use.
40     :sonarcloud-project-key: SonarCloud project key.
41     :sonarcloud-project-organization: SonarCloud project organization.
42     :sonarcloud-api-token: SonarCloud API Token.
43
44 lf-maven-build
45 --------------
46
47 Calls the maven build script to perform a maven build.
48
49 :Required parameters:
50
51     :mvn-goals: The maven goals to perform for the build.
52         (default: clean deploy)
53
54 lf-maven-common
55 ---------------
56
57 Common Jenkins configuration for Maven jobs.
58
59 lf-maven-deploy
60 ---------------
61
62 Calls the maven deploy script to push artifacts to Nexus.
63
64 lf-maven-versions-plugin
65 ------------------------
66
67 Conditionally calls Maven versions plugin to set, update and commit the maven `versions:set`.
68
69 :Required Parameters:
70
71     :maven-versions-plugin: Whether to call Maven versions plugin or not. (default: false)
72     :mvn-version: Version of Maven to execute Sonar with.
73     :mvn-pom: Location of pom.xml.
74     :mvn-settings: Maven settings.xml file containing credentials to use.
75
76 lf-maven-stage
77 --------------
78
79 Calls the maven stage script to push artifacts to a Nexus staging repository.
80
81 :Required Parameters:
82
83     :mvn-global-settings: The name of the Maven global settings to use for
84         Maven configuration.
85     :mvn-settings: The name of settings file containing credentials for the project.
86
87 lf-update-java-alternatives
88 ---------------------------
89
90 Setup Java alternatives for the Distro.
91
92 :Required Parameters:
93
94     :java-version: Version of Java to set as the default Java.
95         Eg. openjdk8
96
97 Job Templates
98 =============
99
100 Maven CLM
101 ---------
102
103 Produces a CLM scan of the code into Nexus IQ Server.
104
105 :Template Names:
106
107     - {project-name}-maven-clm-{stream}
108     - gerrit-maven-clm
109     - github-maven-clm
110
111 :Comment Trigger: run-clm
112
113 :Required parameters:
114
115     :build-node:    The node to run build on.
116     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
117         be configured in defaults.yaml)
118     :mvn-settings: The name of settings file containing credentials for the project.
119
120 :Optional parameters:
121
122     :branch: The branch to build against. (default: master)
123     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
124     :build-timeout: Timeout in minutes before aborting build. (default: 60)
125     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
126     :java-version: Version of Java to use for the build. (default: openjdk8)
127     :mvn-global-settings: The name of the Maven global settings to use for
128         Maven configuration. (default: global-settings)
129     :mvn-opts: Sets MAVEN_OPTS. (default: '')
130     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
131     :mvn-version: Version of maven to use. (default: mvn35)
132     :nexus-iq-namespace: Insert a namespace to project AppID for projects that
133         share a Nexus IQ system to avoid project name collision. We recommend
134         inserting a trailing - dash if using this parameter.
135         For example 'odl-'. (default: '')
136     :nexus-iq-stage: Stage the policy evaluation will be run against on
137         the Nexus IQ Server. (default: 'build')
138     :stream: Keyword that can be used to represent a release code-name.
139         Often the same as the branch. (default: master)
140     :submodule-recursive: Whether to checkout submodules recursively.
141         (default: true)
142     :submodule-timeout: Timeout (in minutes) for checkout operation.
143         (default: 10)
144     :submodule-disable: Disable submodule checkout operation.
145         (default: false)
146
147     :gerrit_merge_triggers: Override Gerrit Triggers.
148
149 Maven JavaDoc Publish
150 ---------------------
151
152 Produces and publishes javadocs for a Maven project.
153
154 Expects javadocs to be available in $WORKSPACE/target/site/apidocs
155
156 :Template Names:
157
158     - {project-name}-maven-javadoc-publish-{stream}-{java-version}
159     - gerrit-maven-javadoc-publish
160     - github-maven-javadoc-publish
161
162 :Comment Trigger: remerge
163
164 :Required parameters:
165
166     :build-node: The node to run build on.
167     :javadoc-path: The path in Nexus to deploy javadoc to.
168     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
169         be configured in defaults.yaml)
170     :mvn-settings: The name of settings file containing credentials for the project.
171     :mvn-site-id: Maven Server ID from settings.xml to pull credentials from.
172         (Note: This setting should be configured in defaults.yaml.)
173
174 :Optional parameters:
175
176     :branch: The branch to build against. (default: master)
177     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
178     :build-timeout: Timeout in minutes before aborting build. (default: 60)
179     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
180     :java-version: Version of Java to use for the build. (default: openjdk8)
181     :mvn-global-settings: The name of the Maven global settings to use for
182         Maven configuration. (default: global-settings)
183     :mvn-opts: Sets MAVEN_OPTS. (default: '')
184     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
185     :mvn-version: Version of maven to use. (default: mvn35)
186     :stream: Keyword that can be used to represent a release code-name.
187         Often the same as the branch. (default: master)
188     :submodule-recursive: Whether to checkout submodules recursively.
189         (default: true)
190     :submodule-timeout: Timeout (in minutes) for checkout operation.
191         (default: 10)
192     :submodule-disable: Disable submodule checkout operation.
193         (default: false)
194
195     :gerrit_merge_triggers: Override Gerrit Triggers.
196
197 Maven JavaDoc Verify
198 --------------------
199
200 Produces javadocs for a Maven project.
201
202 Expects javadocs to be available in $WORKSPACE/target/site/apidocs
203
204 :Template Names:
205
206     - {project-name}-maven-javadoc-verify-{stream}-{java-version}
207     - gerrit-maven-javadoc-verify
208     - github-maven-javadoc-verify
209
210 :Comment Trigger: recheck|reverify
211
212 :Required parameters:
213     :build-node:    The node to run build on.
214     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
215         be configured in defaults.yaml)
216     :mvn-settings: The name of settings file containing credentials for the project.
217
218 :Optional parameters:
219
220     :branch: The branch to build against. (default: master)
221     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
222     :build-timeout: Timeout in minutes before aborting build. (default: 60)
223     :deploy-path:    The path in Nexus to deploy javadoc to. (default: $PROJECT/$STREAM)
224     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
225     :java-version: Version of Java to use for the build. (default: openjdk8)
226     :mvn-global-settings: The name of the Maven global settings to use for
227         Maven configuration. (default: global-settings)
228     :mvn-opts: Sets MAVEN_OPTS. (default: '')
229     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
230     :mvn-version: Version of maven to use. (default: mvn35)
231     :stream: Keyword that can be used to represent a release code-name.
232         Often the same as the branch. (default: master)
233     :submodule-recursive: Whether to checkout submodules recursively.
234         (default: true)
235     :submodule-timeout: Timeout (in minutes) for checkout operation.
236         (default: 10)
237     :submodule-disable: Disable submodule checkout operation.
238         (default: false)
239
240     :gerrit_verify_triggers: Override Gerrit Triggers.
241
242 Maven Merge
243 -----------
244
245 Merge job which runs `mvn clean deploy` to build a project.
246
247 This job pushes files to Nexus using cURL instead of allowing the Maven deploy
248 goal to push the upload. This is to get around the issue that Maven deploy does
249 not properly support uploading files at the end of the build and instead pushes
250 as it goes. There exists a `-Ddeploy-at-end` feature however it does not work
251 with extensions.
252
253 This job uses the following strategy to deploy jobs to Nexus:
254
255 1. `wget -r` to fetch maven-metadata.xml from Nexus
256 2. `mvn deploy -DaltDeploymentRepository` to prepare files for upload
257 3. Removes untouched maven-metadata.xml files before upload
258 4. Use lftools (cURL) upload script to push artifacts to Nexus
259
260 :Template Names:
261
262     - {project-name}-maven-merge-{stream}
263     - gerrit-maven-merge
264     - github-maven-merge
265
266 :Comment Trigger: remerge
267
268 :Required parameters:
269
270     :build-node: The node to run build on.
271     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
272         be configured in defaults.yaml)
273     :mvn-settings: The name of settings file containing credentials for the project.
274     :mvn-snapshot-id: Maven Server ID from settings.xml to pull credentials from.
275         (Note: This setting should be configured in defaults.yaml.)
276     :nexus-snapshot-repo: The repository id of the Nexus snapshot repo to deploy to.
277
278 :Optional parameters:
279
280     :branch: Git branch to fetch for the build. (default: master)
281     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
282     :build-timeout: Timeout in minutes before aborting build. (default: 60)
283     :cron: Cron schedule when to trigger the job. This parameter also
284         supports multiline input via YAML pipe | character in cases where
285         one may want to provide more than 1 cron timer. (default: 'H H * * 0'
286         to run weekly)
287     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
288     :java-version: Version of Java to use for the build. (default: openjdk8)
289     :mvn-global-settings: The name of the Maven global settings to use for
290         Maven configuration. (default: global-settings)
291     :mvn-opts: Sets MAVEN_OPTS. (default: '')
292     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
293     :mvn-version: Version of maven to use. (default: mvn35)
294     :nexus-cut-dirs: Number of directories to cut from file path for `wget -r`.
295     :stream: Keyword that can be used to represent a release code-name.
296         Often the same as the branch. (default: master)
297     :submodule-recursive: Whether to checkout submodules recursively.
298         (default: true)
299     :submodule-timeout: Timeout (in minutes) for checkout operation.
300         (default: 10)
301     :submodule-disable: Disable submodule checkout operation.
302         (default: false)
303
304     :gerrit_merge_triggers: Override Gerrit Triggers.
305     :gerrit_trigger_file_paths: Override file paths which can be used to
306         filter which file modifications will trigger a build.
307
308 Maven Merge for Docker
309 ----------------------
310
311 Produces a snapshot docker image in a Nexus registry. Appropriate for
312 Java projects that do not need to deploy any POM or JAR files.
313
314 Similar to Maven Merge as described above but logs in to Docker
315 registries first and skips the lf-maven-deploy builder. The project
316 POM file should invoke a plugin to build and push a Docker image. The
317 base image should be pulled from the registry in the environment
318 variable CONTAINER_PULL_REGISTRY. The new image should be pushed to the
319 registry in the environment variable CONTAINER_PUSH_REGISTRY.
320
321 :Template Names:
322
323     - {project-name}-maven-docker-merge-{stream}
324     - gerrit-maven-docker-merge
325     - github-maven-docker-merge
326
327 :Required parameters:
328
329     :container-public-registry: Docker registry source with base images.
330     :container-snapshot-registry: Docker registry target for the deploy action.
331
332 All other required and optional parameters are identical to the Maven Merge job
333 described above.
334
335 Maven Stage
336 -----------
337
338 Produces a release candidate by creating a staging repo in Nexus.
339
340 The staging repo name is in the format PROJECT-NUMBER for example "aaa-1234",
341 "autorelease-2000", "odlparent-1201", etc...
342
343 This job runs a Maven build and deploys to $WORKSPACE/m2repo directory. This
344 directory is then used later to deploy to Nexus.
345
346 :Template Names:
347
348     - {project-name}-maven-stage-{stream}
349     - gerrit-maven-stage
350     - github-maven-stage
351
352 :Required parameters:
353
354     :build-node: The node to run build on.
355     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
356         be configured in defaults.yaml)
357     :mvn-settings: The name of settings file containing credentials for the project.
358     :mvn-staging-id: Maven Server ID from settings.xml to pull credentials from.
359         (Note: This setting should be configured in defaults.yaml.)
360     :staging-profile-id: Profile ID of the project's Nexus staging profile.
361
362 :Optional parameters:
363
364     :archive-artifacts: Artifacts to archive to the logs server (default: '').
365     :branch: The branch to build against. (default: master)
366     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
367     :build-timeout: Timeout in minutes before aborting build. (default: 60)
368     :cron: Cron schedule when to trigger the job. This parameter also
369         supports multiline input via YAML pipe | character in cases where
370         one may want to provide more than 1 cron timer. (default: '')
371     :deploy-path:    The path in Nexus to deploy javadoc to. (default: $PROJECT/$STREAM)
372     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
373     :java-version: Version of Java to use for the build. (default: openjdk8)
374     :mvn-central: Set to 'true' to also stage to OSSRH. This is for projects
375         that want to release to Maven Central. If set the parameter
376         ``ossrh-profile-id`` also needs to be set. (default: false)
377     :maven-versions-plugin: Whether to call Maven versions plugin or not. (default: false)
378     :mvn-global-settings: The name of the Maven global settings to use for
379         Maven configuration. (default: global-settings)
380     :mvn-opts: Sets MAVEN_OPTS. (default: '')
381     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
382     :mvn-version: Version of maven to use. (default: mvn35)
383     :ossrh-profile-id: Profile ID for project as provided by OSSRH.
384         (default: '')
385     :sign-artifacts: Sign artifacts with Sigul. (default: false)
386     :stream: Keyword that can be used to represent a release code-name.
387         Often the same as the branch. (default: master)
388     :submodule-recursive: Whether to checkout submodules recursively.
389         (default: true)
390     :submodule-timeout: Timeout (in minutes) for checkout operation.
391         (default: 10)
392     :submodule-disable: Disable submodule checkout operation.
393         (default: false)
394
395     :gerrit_release_triggers: Override Gerrit Triggers.
396
397 Maven Stage for Docker
398 ----------------------
399
400 Produces a release candidate docker image in a Nexus registry.
401 Appropriate for Java projects that do not need to deploy any POM or
402 JAR files.
403
404 Similar to Maven Stage as described above but logs in to Docker
405 registries first and skips the lf-maven-deploy builder. The project
406 POM file should invoke a plugin to build and push a Docker image. The
407 base image should be pulled from the registry in the environment
408 variable CONTAINER_PULL_REGISTRY. The new image should be pushed to the
409 registry in the environment variable CONTAINER_PUSH_REGISTRY.
410
411 :Template Names:
412
413     - {project-name}-maven-docker-stage-{stream}
414     - gerrit-maven-docker-stage
415     - github-maven-docker-stage
416
417 :Required parameters:
418
419     :container-public-registry: Docker registry source with base images.
420     :container-staging-registry: Docker registry target for the deploy action.
421
422 All other required and optional parameters are identical to the Maven Stage job
423 described above.
424
425 .. _maven-sonar:
426
427 Maven Sonar
428 -----------
429
430 Sonar job which runs mvn clean install then publishes to Sonar.
431
432 This job purposely only runs on the master branch as there are Additional
433 configuration needed to support multiple branches and there's not much
434 interest in that kind of support.
435
436 :Template Names:
437
438     - {project-name}-sonar
439     - gerrit-maven-sonar
440     - github-maven-sonar
441
442 :Comment Trigger: run-sonar
443
444 :Required parameters:
445
446     :build-node: The node to run build on.
447     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
448         be configured in defaults.yaml)
449     :mvn-settings: The name of settings file containing credentials for the project.
450
451 :Optional parameters:
452
453     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
454     :build-timeout: Timeout in minutes before aborting build. (default: 60)
455     :cron: Cron schedule when to trigger the job. This parameter also
456         supports multiline input via YAML pipe | character in cases where
457         one may want to provide more than 1 cron timer.  (default: 'H H * * 6'
458         to run weekly)
459     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
460     :java-version: Version of Java to use for the build. (default: openjdk8)
461     :mvn-global-settings: The name of the Maven global settings to use for
462         Maven configuration. (default: global-settings)
463     :mvn-opts: Sets MAVEN_OPTS. (default: '')
464     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
465     :mvn-version: Version of maven to use. (default: mvn35)
466     :sonar-mvn-goals: Maven goals to run for sonar analysis.
467         (default: sonar:sonar)
468     :sonarcloud: Whether or not to use SonarCloud ``true|false``.
469         (default: false)
470     :sonarcloud-project-key: SonarCloud project key. (default: '')
471     :sonarcloud-project-organization: SonarCloud project organization.
472         (default: '')
473     :sonarcloud-api-token: SonarCloud API Token. (default: '')
474     :stream: Keyword that can be used to represent a release code-name.
475         Often the same as the branch. (default: master)
476     :submodule-recursive: Whether to checkout submodules recursively.
477         (default: true)
478     :submodule-timeout: Timeout (in minutes) for checkout operation.
479         (default: 10)
480     :submodule-disable: Disable submodule checkout operation.
481         (default: false)
482
483     :gerrit_sonar_triggers: Override Gerrit Triggers.
484
485
486 SonarCloud Example:
487
488 .. literalinclude:: ../../.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml
489    :language: yaml
490
491 Maven Verify
492 ------------
493
494 Verify job which runs mvn clean install to test a project build..
495
496 :Template Names:
497
498     - {project-name}-maven-verify-{stream}-{mvn-version}-{java-version}
499     - gerrit-maven-verify
500     - github-maven-verify
501
502 :Comment Trigger: recheck|reverify
503
504 :Required parameters:
505
506     :build-node: The node to run build on.
507     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
508         be configured in defaults.yaml)
509     :mvn-settings: The name of settings file containing credentials for the project.
510
511 :Optional parameters:
512
513     :branch: Git branch to fetch for the build. (default: master)
514     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
515     :build-timeout: Timeout in minutes before aborting build. (default: 60)
516     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
517     :java-version: Version of Java to use for the build. (default: openjdk8)
518     :mvn-global-settings: The name of the Maven global settings to use for
519         Maven configuration. (default: global-settings)
520     :mvn-opts: Sets MAVEN_OPTS. (default: '')
521     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
522     :mvn-version: Version of maven to use. (default: mvn35)
523     :stream: Keyword that can be used to represent a release code-name.
524         Often the same as the branch. (default: master)
525     :submodule-recursive: Whether to checkout submodules recursively.
526         (default: true)
527     :submodule-timeout: Timeout (in minutes) for checkout operation.
528         (default: 10)
529     :submodule-disable: Disable submodule checkout operation.
530         (default: false)
531
532     :gerrit_verify_triggers: Override Gerrit Triggers.
533     :gerrit_trigger_file_paths: Override file paths which can be used to
534         filter which file modifications will trigger a build.
535
536 Maven Verify for Docker
537 -----------------------
538
539 Similar to Maven Verify as described above but logs in to Docker
540 registries first. The project POM file should invoke a plugin to build
541 a Docker image. The base image should be pulled from the registry in
542 the environment variable CONTAINER_PULL_REGISTRY.
543
544 :Template Names:
545
546     - {project-name}-maven-docker-verify-{stream}-{mvn-version}-{java-version}
547     - gerrit-maven-docker-verify
548     - github-maven-docker-verify
549
550 :Required parameters:
551
552     :container-public-registry: Docker registry source with base images.
553
554 All other required and optional parameters are identical to the Maven Verify job
555 described above.
556
557 Maven Verify w/ Dependencies
558 ----------------------------
559
560 Verify job which runs mvn clean install to test a project build /w deps
561
562 This job can be used to verify a patch in conjunction to all of the
563 upstream patches it depends on. The user of this job can provide a list
564 via comment trigger.
565
566 :Template Names:
567
568     - {project-name}-maven-verify-deps-{stream}-{mvn-version}-{java-version}
569     - gerrit-maven-verify-dependencies
570
571 :Comment Trigger: recheck: SPACE_SEPARATED_LIST_OF_PATCHES
572
573 :Required parameters:
574
575     :build-node: The node to run build on.
576     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
577         be configured in defaults.yaml)
578     :mvn-settings: The name of settings file containing credentials for the project.
579
580 :Optional parameters:
581
582     :branch: Git branch to fetch for the build. (default: master)
583     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
584     :build-timeout: Timeout in minutes before aborting build. (default: 60)
585     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
586     :java-version: Version of Java to use for the build. (default: openjdk8)
587     :mvn-global-settings: The name of the Maven global settings to use for
588         Maven configuration. (default: global-settings)
589     :mvn-opts: Sets MAVEN_OPTS. (default: '')
590     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
591     :mvn-version: Version of maven to use. (default: mvn35)
592     :stream: Keyword that can be used to represent a release code-name.
593         Often the same as the branch. (default: master)
594     :submodule-recursive: Whether to checkout submodules recursively.
595         (default: true)
596     :submodule-timeout: Timeout (in minutes) for checkout operation.
597         (default: 10)
598     :submodule-disable: Disable submodule checkout operation.
599         (default: false)
600
601     :gerrit_verify_triggers: Override Gerrit Triggers.
602     :gerrit_trigger_file_paths: Override file paths which can be used to
603         filter which file modifications will trigger a build.