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