1a0dc1ec0f74b173cb1f4a3941efc273b6ee05c7
[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
145     :gerrit_merge_triggers: Override Gerrit Triggers.
146
147 Maven JavaDoc Publish
148 ---------------------
149
150 Produces and publishes javadocs for a Maven project.
151
152 Expects javadocs to be available in $WORKSPACE/target/site/apidocs
153
154 :Template Names:
155
156     - {project-name}-maven-javadoc-publish-{stream}-{java-version}
157     - gerrit-maven-javadoc-publish
158     - github-maven-javadoc-publish
159
160 :Comment Trigger: remerge
161
162 :Required parameters:
163
164     :build-node: The node to run build on.
165     :javadoc-path: The path in Nexus to deploy javadoc to.
166     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
167         be configured in defaults.yaml)
168     :mvn-settings: The name of settings file containing credentials for the project.
169     :mvn-site-id: Maven Server ID from settings.xml to pull credentials from.
170         (Note: This setting should be configured in defaults.yaml.)
171
172 :Optional parameters:
173
174     :branch: The branch to build against. (default: master)
175     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
176     :build-timeout: Timeout in minutes before aborting build. (default: 60)
177     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
178     :java-version: Version of Java to use for the build. (default: openjdk8)
179     :mvn-global-settings: The name of the Maven global settings to use for
180         Maven configuration. (default: global-settings)
181     :mvn-opts: Sets MAVEN_OPTS. (default: '')
182     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
183     :mvn-version: Version of maven to use. (default: mvn35)
184     :stream: Keyword that can be used to represent a release code-name.
185         Often the same as the branch. (default: master)
186     :submodule-recursive: Whether to checkout submodules recursively.
187         (default: true)
188     :submodule-timeout: Timeout (in minutes) for checkout operation.
189         (default: 10)
190
191     :gerrit_merge_triggers: Override Gerrit Triggers.
192
193 Maven JavaDoc Verify
194 --------------------
195
196 Produces javadocs for a Maven project.
197
198 Expects javadocs to be available in $WORKSPACE/target/site/apidocs
199
200 :Template Names:
201
202     - {project-name}-maven-javadoc-verify-{stream}-{java-version}
203     - gerrit-maven-javadoc-verify
204     - github-maven-javadoc-verify
205
206 :Comment Trigger: recheck|reverify
207
208 :Required parameters:
209     :build-node:    The node to run build on.
210     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
211         be configured in defaults.yaml)
212     :mvn-settings: The name of settings file containing credentials for the project.
213
214 :Optional parameters:
215
216     :branch: The branch to build against. (default: master)
217     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
218     :build-timeout: Timeout in minutes before aborting build. (default: 60)
219     :deploy-path:    The path in Nexus to deploy javadoc to. (default: $PROJECT/$STREAM)
220     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
221     :java-version: Version of Java to use for the build. (default: openjdk8)
222     :mvn-global-settings: The name of the Maven global settings to use for
223         Maven configuration. (default: global-settings)
224     :mvn-opts: Sets MAVEN_OPTS. (default: '')
225     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
226     :mvn-version: Version of maven to use. (default: mvn35)
227     :stream: Keyword that can be used to represent a release code-name.
228         Often the same as the branch. (default: master)
229     :submodule-recursive: Whether to checkout submodules recursively.
230         (default: true)
231     :submodule-timeout: Timeout (in minutes) for checkout operation.
232         (default: 10)
233
234     :gerrit_verify_triggers: Override Gerrit Triggers.
235
236 Maven Merge
237 -----------
238
239 Merge job which runs `mvn clean deploy` to build a project.
240
241 This job pushes files to Nexus using cURL instead of allowing the Maven deploy
242 goal to push the upload. This is to get around the issue that Maven deploy does
243 not properly support uploading files at the end of the build and instead pushes
244 as it goes. There exists a `-Ddeploy-at-end` feature however it does not work
245 with extensions.
246
247 This job uses the following strategy to deploy jobs to Nexus:
248
249 1. `wget -r` to fetch maven-metadata.xml from Nexus
250 2. `mvn deploy -DaltDeploymentRepository` to prepare files for upload
251 3. Removes untouched maven-metadata.xml files before upload
252 4. Use lftools (cURL) upload script to push artifacts to Nexus
253
254 :Template Names:
255
256     - {project-name}-maven-merge-{stream}
257     - gerrit-maven-merge
258     - github-maven-merge
259
260 :Comment Trigger: remerge
261
262 :Required parameters:
263
264     :build-node: The node to run build on.
265     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
266         be configured in defaults.yaml)
267     :mvn-settings: The name of settings file containing credentials for the project.
268     :mvn-snapshot-id: Maven Server ID from settings.xml to pull credentials from.
269         (Note: This setting should be configured in defaults.yaml.)
270     :nexus-snapshot-repo: The repository id of the Nexus snapshot repo to deploy to.
271
272 :Optional parameters:
273
274     :branch: Git branch to fetch for the build. (default: master)
275     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
276     :build-timeout: Timeout in minutes before aborting build. (default: 60)
277     :cron: Cron schedule when to trigger the job. This parameter also
278         supports multiline input via YAML pipe | character in cases where
279         one may want to provide more than 1 cron timer. (default: 'H H * * 0'
280         to run weekly)
281     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
282     :java-version: Version of Java to use for the build. (default: openjdk8)
283     :mvn-global-settings: The name of the Maven global settings to use for
284         Maven configuration. (default: global-settings)
285     :mvn-opts: Sets MAVEN_OPTS. (default: '')
286     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
287     :mvn-version: Version of maven to use. (default: mvn35)
288     :nexus-cut-dirs: Number of directories to cut from file path for `wget -r`.
289     :stream: Keyword that can be used to represent a release code-name.
290         Often the same as the branch. (default: master)
291     :submodule-recursive: Whether to checkout submodules recursively.
292         (default: true)
293     :submodule-timeout: Timeout (in minutes) for checkout operation.
294         (default: 10)
295     :gerrit_merge_triggers: Override Gerrit Triggers.
296     :gerrit_trigger_file_paths: Override file paths which can be used to
297         filter which file modifications will trigger a build.
298
299 Maven Merge for Docker
300 ----------------------
301
302 Produces a snapshot docker image in a Nexus registry. Appropriate for
303 Java projects that do not need to deploy any POM or JAR files.
304
305 Similar to Maven Merge as described above but logs in to Docker
306 registries first and skips the lf-maven-deploy builder. The project
307 POM file should invoke a plugin to build and push a Docker image. The
308 base image should be pulled from the registry in the environment
309 variable CONTAINER_PULL_REGISTRY. The new image should be pushed to the
310 registry in the environment variable CONTAINER_PUSH_REGISTRY.
311
312 :Template Names:
313
314     - {project-name}-maven-docker-merge-{stream}
315     - gerrit-maven-docker-merge
316     - github-maven-docker-merge
317
318 :Required parameters:
319
320     :container-public-registry: Docker registry source with base images.
321     :container-snapshot-registry: Docker registry target for the deploy action.
322
323 All other required and optional parameters are identical to the Maven Merge job
324 described above.
325
326 Maven Stage
327 -----------
328
329 Produces a release candidate by creating a staging repo in Nexus.
330
331 The staging repo name is in the format PROJECT-NUMBER for example "aaa-1234",
332 "autorelease-2000", "odlparent-1201", etc...
333
334 This job runs a Maven build and deploys to $WORKSPACE/m2repo directory. This
335 directory is then used later to deploy to Nexus.
336
337 :Template Names:
338
339     - {project-name}-maven-stage-{stream}
340     - gerrit-maven-stage
341     - github-maven-stage
342
343 :Required parameters:
344
345     :build-node: The node to run build on.
346     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
347         be configured in defaults.yaml)
348     :mvn-settings: The name of settings file containing credentials for the project.
349     :mvn-staging-id: Maven Server ID from settings.xml to pull credentials from.
350         (Note: This setting should be configured in defaults.yaml.)
351     :staging-profile-id: Profile ID of the project's Nexus staging profile.
352
353 :Optional parameters:
354
355     :archive-artifacts: Artifacts to archive to the logs server (default: '').
356     :branch: The branch to build against. (default: master)
357     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
358     :build-timeout: Timeout in minutes before aborting build. (default: 60)
359     :cron: Cron schedule when to trigger the job. This parameter also
360         supports multiline input via YAML pipe | character in cases where
361         one may want to provide more than 1 cron timer. (default: '')
362     :deploy-path:    The path in Nexus to deploy javadoc to. (default: $PROJECT/$STREAM)
363     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
364     :java-version: Version of Java to use for the build. (default: openjdk8)
365     :mvn-central: Set to 'true' to also stage to OSSRH. This is for projects
366         that want to release to Maven Central. If set the parameter
367         ``ossrh-profile-id`` also needs to be set. (default: false)
368     :maven-versions-plugin: Whether to call Maven versions plugin or not. (default: false)
369     :mvn-global-settings: The name of the Maven global settings to use for
370         Maven configuration. (default: global-settings)
371     :mvn-opts: Sets MAVEN_OPTS. (default: '')
372     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
373     :mvn-version: Version of maven to use. (default: mvn35)
374     :ossrh-profile-id: Profile ID for project as provided by OSSRH.
375         (default: '')
376     :sign-artifacts: Sign artifacts with Sigul. (default: false)
377     :stream: Keyword that can be used to represent a release code-name.
378         Often the same as the branch. (default: master)
379     :submodule-recursive: Whether to checkout submodules recursively.
380         (default: true)
381     :submodule-timeout: Timeout (in minutes) for checkout operation.
382         (default: 10)
383
384     :gerrit_release_triggers: Override Gerrit Triggers.
385
386 Maven Stage for Docker
387 ----------------------
388
389 Produces a release candidate docker image in a Nexus registry.
390 Appropriate for Java projects that do not need to deploy any POM or
391 JAR files.
392
393 Similar to Maven Stage as described above but logs in to Docker
394 registries first and skips the lf-maven-deploy builder. The project
395 POM file should invoke a plugin to build and push a Docker image. The
396 base image should be pulled from the registry in the environment
397 variable CONTAINER_PULL_REGISTRY. The new image should be pushed to the
398 registry in the environment variable CONTAINER_PUSH_REGISTRY.
399
400 :Template Names:
401
402     - {project-name}-maven-docker-stage-{stream}
403     - gerrit-maven-docker-stage
404     - github-maven-docker-stage
405
406 :Required parameters:
407
408     :container-public-registry: Docker registry source with base images.
409     :container-staging-registry: Docker registry target for the deploy action.
410
411 All other required and optional parameters are identical to the Maven Stage job
412 described above.
413
414 .. _maven-sonar:
415
416 Maven Sonar
417 -----------
418
419 Sonar job which runs mvn clean install then publishes to Sonar.
420
421 This job purposely only runs on the master branch as there are Additional
422 configuration needed to support multiple branches and there's not much
423 interest in that kind of support.
424
425 :Template Names:
426
427     - {project-name}-sonar
428     - gerrit-maven-sonar
429     - github-maven-sonar
430
431 :Comment Trigger: run-sonar
432
433 :Required parameters:
434
435     :build-node: The node to run build on.
436     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
437         be configured in defaults.yaml)
438     :mvn-settings: The name of settings file containing credentials for the project.
439
440 :Optional parameters:
441
442     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
443     :build-timeout: Timeout in minutes before aborting build. (default: 60)
444     :cron: Cron schedule when to trigger the job. This parameter also
445         supports multiline input via YAML pipe | character in cases where
446         one may want to provide more than 1 cron timer.  (default: 'H H * * 6'
447         to run weekly)
448     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
449     :java-version: Version of Java to use for the build. (default: openjdk8)
450     :mvn-global-settings: The name of the Maven global settings to use for
451         Maven configuration. (default: global-settings)
452     :mvn-opts: Sets MAVEN_OPTS. (default: '')
453     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
454     :mvn-version: Version of maven to use. (default: mvn35)
455     :sonar-mvn-goals: Maven goals to run for sonar analysis.
456         (default: sonar:sonar)
457     :sonarcloud: Whether or not to use SonarCloud ``true|false``.
458         (default: false)
459     :sonarcloud-project-key: SonarCloud project key. (default: '')
460     :sonarcloud-project-organization: SonarCloud project organization.
461         (default: '')
462     :sonarcloud-api-token: SonarCloud API Token. (default: '')
463     :stream: Keyword that can be used to represent a release code-name.
464         Often the same as the branch. (default: master)
465     :submodule-recursive: Whether to checkout submodules recursively.
466         (default: true)
467     :submodule-timeout: Timeout (in minutes) for checkout operation.
468         (default: 10)
469
470     :gerrit_sonar_triggers: Override Gerrit Triggers.
471
472
473 SonarCloud Example:
474
475 .. literalinclude:: ../../.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml
476    :language: yaml
477
478 Maven Verify
479 ------------
480
481 Verify job which runs mvn clean install to test a project build..
482
483 :Template Names:
484
485     - {project-name}-maven-verify-{stream}-{mvn-version}-{java-version}
486     - gerrit-maven-verify
487     - github-maven-verify
488
489 :Comment Trigger: recheck|reverify
490
491 :Required parameters:
492
493     :build-node: The node to run build on.
494     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
495         be configured in defaults.yaml)
496     :mvn-settings: The name of settings file containing credentials for the project.
497
498 :Optional parameters:
499
500     :branch: Git branch to fetch for the build. (default: master)
501     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
502     :build-timeout: Timeout in minutes before aborting build. (default: 60)
503     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
504     :java-version: Version of Java to use for the build. (default: openjdk8)
505     :mvn-global-settings: The name of the Maven global settings to use for
506         Maven configuration. (default: global-settings)
507     :mvn-opts: Sets MAVEN_OPTS. (default: '')
508     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
509     :mvn-version: Version of maven to use. (default: mvn35)
510     :stream: Keyword that can be used to represent a release code-name.
511         Often the same as the branch. (default: master)
512     :submodule-recursive: Whether to checkout submodules recursively.
513         (default: true)
514     :submodule-timeout: Timeout (in minutes) for checkout operation.
515         (default: 10)
516
517     :gerrit_verify_triggers: Override Gerrit Triggers.
518     :gerrit_trigger_file_paths: Override file paths which can be used to
519         filter which file modifications will trigger a build.
520
521 Maven Verify for Docker
522 -----------------------
523
524 Similar to Maven Verify as described above but logs in to Docker
525 registries first. The project POM file should invoke a plugin to build
526 a Docker image. The base image should be pulled from the registry in
527 the environment variable CONTAINER_PULL_REGISTRY.
528
529 :Template Names:
530
531     - {project-name}-maven-docker-verify-{stream}-{mvn-version}-{java-version}
532     - gerrit-maven-docker-verify
533     - github-maven-docker-verify
534
535 :Required parameters:
536
537     :container-public-registry: Docker registry source with base images.
538
539 All other required and optional parameters are identical to the Maven Verify job
540 described above.
541
542 Maven Verify w/ Dependencies
543 ----------------------------
544
545 Verify job which runs mvn clean install to test a project build /w deps
546
547 This job can be used to verify a patch in conjunction to all of the
548 upstream patches it depends on. The user of this job can provide a list
549 via comment trigger.
550
551 :Template Names:
552
553     - {project-name}-maven-verify-deps-{stream}-{mvn-version}-{java-version}
554     - gerrit-maven-verify-dependencies
555
556 :Comment Trigger: recheck: SPACE_SEPARATED_LIST_OF_PATCHES
557
558 :Required parameters:
559
560     :build-node: The node to run build on.
561     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
562         be configured in defaults.yaml)
563     :mvn-settings: The name of settings file containing credentials for the project.
564
565 :Optional parameters:
566
567     :branch: Git branch to fetch for the build. (default: master)
568     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
569     :build-timeout: Timeout in minutes before aborting build. (default: 60)
570     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
571     :java-version: Version of Java to use for the build. (default: openjdk8)
572     :mvn-global-settings: The name of the Maven global settings to use for
573         Maven configuration. (default: global-settings)
574     :mvn-opts: Sets MAVEN_OPTS. (default: '')
575     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
576     :mvn-version: Version of maven to use. (default: mvn35)
577     :stream: Keyword that can be used to represent a release code-name.
578         Often the same as the branch. (default: master)
579     :submodule-recursive: Whether to checkout submodules recursively.
580         (default: true)
581     :submodule-timeout: Timeout (in minutes) for checkout operation.
582         (default: 10)
583
584     :gerrit_verify_triggers: Override Gerrit Triggers.
585     :gerrit_trigger_file_paths: Override file paths which can be used to
586         filter which file modifications will trigger a build.