fd0b89081ac3087f8ef66255e5d72f75da2acc1a
[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 :Comment Trigger: "stage-release" or "stage-maven-release"
355
356 :Required parameters:
357
358     :build-node: The node to run build on.
359     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
360         be configured in defaults.yaml)
361     :mvn-settings: The name of settings file containing credentials for the project.
362     :mvn-staging-id: Maven Server ID from settings.xml to pull credentials from.
363         (Note: This setting should be configured in defaults.yaml.)
364     :staging-profile-id: Profile ID of the project's Nexus staging profile.
365
366 :Optional parameters:
367
368     :archive-artifacts: Artifacts to archive to the logs server (default: '').
369     :branch: The branch to build against. (default: master)
370     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
371     :build-timeout: Timeout in minutes before aborting build. (default: 60)
372     :cron: Cron schedule when to trigger the job. This parameter also
373         supports multiline input via YAML pipe | character in cases where
374         one may want to provide more than 1 cron timer. (default: '')
375     :deploy-path:    The path in Nexus to deploy javadoc to. (default: $PROJECT/$STREAM)
376     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
377     :java-version: Version of Java to use for the build. (default: openjdk8)
378     :mvn-central: Set to 'true' to also stage to OSSRH. This is for projects
379         that want to release to Maven Central. If set the parameter
380         ``ossrh-profile-id`` also needs to be set. (default: false)
381     :maven-versions-plugin: Whether to call Maven versions plugin or not. (default: false)
382     :mvn-global-settings: The name of the Maven global settings to use for
383         Maven configuration. (default: global-settings)
384     :mvn-opts: Sets MAVEN_OPTS. (default: '')
385     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
386     :mvn-version: Version of maven to use. (default: mvn35)
387     :ossrh-profile-id: Profile ID for project as provided by OSSRH.
388         (default: '')
389     :sign-artifacts: Sign artifacts with Sigul. (default: false)
390     :stream: Keyword that can be used to represent a release code-name.
391         Often the same as the branch. (default: master)
392     :submodule-recursive: Whether to checkout submodules recursively.
393         (default: true)
394     :submodule-timeout: Timeout (in minutes) for checkout operation.
395         (default: 10)
396     :submodule-disable: Disable submodule checkout operation.
397         (default: false)
398     :version-properties-file: Name and path of the version properties file.
399         (default: version.properties)
400
401     :gerrit_release_triggers: Override Gerrit Triggers.
402     :gerrit_trigger_file_paths: Override file paths which can be used to
403         filter which file modifications will trigger a build.
404
405 Maven Stage for Docker
406 ----------------------
407
408 Produces a release candidate docker image in a Nexus registry.
409 Appropriate for Java projects that do not need to deploy any POM or
410 JAR files.
411
412 Similar to Maven Stage as described above but logs in to Docker
413 registries first and skips the lf-maven-deploy builder. The project
414 POM file should invoke a plugin to build and push a Docker image. The
415 base image should be pulled from the registry in the environment
416 variable CONTAINER_PULL_REGISTRY. The new image should be pushed to the
417 registry in the environment variable CONTAINER_PUSH_REGISTRY.
418
419 :Template Names:
420
421     - {project-name}-maven-docker-stage-{stream}
422     - gerrit-maven-docker-stage
423     - github-maven-docker-stage
424
425 :Comment Trigger: "stage-release" or "stage-docker-release"
426
427 :Required parameters:
428
429     :container-public-registry: Docker registry source with base images.
430     :container-staging-registry: Docker registry target for the deploy action.
431
432 :Optional parameters:
433
434     :gerrit_release_docker_triggers: Override Gerrit Triggers.
435
436 All other required and optional parameters are identical to the Maven Stage job
437 described above.
438
439 .. _maven-sonar:
440
441 Maven Sonar
442 -----------
443
444 Sonar job which runs mvn clean install then publishes to Sonar.
445
446 This job purposely only runs on the master branch as there are Additional
447 configuration needed to support multiple branches and there's not much
448 interest in that kind of support.
449
450 :Template Names:
451
452     - {project-name}-sonar
453     - gerrit-maven-sonar
454     - github-maven-sonar
455
456 :Comment Trigger: run-sonar
457
458 :Required parameters:
459
460     :build-node: The node to run build on.
461     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
462         be configured in defaults.yaml)
463     :mvn-settings: The name of settings file containing credentials for the project.
464
465 :Optional parameters:
466
467     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
468     :build-timeout: Timeout in minutes before aborting build. (default: 60)
469     :cron: Cron schedule when to trigger the job. This parameter also
470         supports multiline input via YAML pipe | character in cases where
471         one may want to provide more than 1 cron timer.  (default: 'H H * * 6'
472         to run weekly)
473     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
474     :java-version: Version of Java to use for the build. (default: openjdk8)
475     :mvn-global-settings: The name of the Maven global settings to use for
476         Maven configuration. (default: global-settings)
477     :mvn-goals: The maven goals to perform for the build.
478         (default: clean install)
479     :mvn-opts: Sets MAVEN_OPTS. (default: '')
480     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
481     :mvn-version: Version of maven to use. (default: mvn35)
482     :sonar-mvn-goals: Maven goals to run for sonar analysis.
483         (default: sonar:sonar)
484     :sonarcloud: Whether or not to use SonarCloud ``true|false``.
485         (default: false)
486     :sonarcloud-project-key: SonarCloud project key. (default: '')
487     :sonarcloud-project-organization: SonarCloud project organization.
488         (default: '')
489     :sonarcloud-api-token: SonarCloud API Token. (default: '')
490     :stream: Keyword that can be used to represent a release code-name.
491         Often the same as the branch. (default: master)
492     :submodule-recursive: Whether to checkout submodules recursively.
493         (default: true)
494     :submodule-timeout: Timeout (in minutes) for checkout operation.
495         (default: 10)
496     :submodule-disable: Disable submodule checkout operation.
497         (default: false)
498
499     :gerrit_sonar_triggers: Override Gerrit Triggers.
500
501
502 SonarCloud Example:
503
504 .. literalinclude:: ../../.jjb-test/lf-maven-jobs/maven-sonarcloud.yaml
505    :language: yaml
506
507 Maven Verify
508 ------------
509
510 Verify job which runs mvn clean install to test a project build..
511
512 :Template Names:
513
514     - {project-name}-maven-verify-{stream}-{mvn-version}-{java-version}
515     - gerrit-maven-verify
516     - github-maven-verify
517
518 :Comment Trigger: recheck|reverify
519
520 :Required parameters:
521
522     :build-node: The node to run build on.
523     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
524         be configured in defaults.yaml)
525     :mvn-settings: The name of settings file containing credentials for the project.
526
527 :Optional parameters:
528
529     :branch: Git branch to fetch for the build. (default: master)
530     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
531     :build-timeout: Timeout in minutes before aborting build. (default: 60)
532     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
533     :java-version: Version of Java to use for the build. (default: openjdk8)
534     :mvn-global-settings: The name of the Maven global settings to use for
535         Maven configuration. (default: global-settings)
536     :mvn-opts: Sets MAVEN_OPTS. (default: '')
537     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
538     :mvn-version: Version of maven to use. (default: mvn35)
539     :stream: Keyword that can be used to represent a release code-name.
540         Often the same as the branch. (default: master)
541     :submodule-recursive: Whether to checkout submodules recursively.
542         (default: true)
543     :submodule-timeout: Timeout (in minutes) for checkout operation.
544         (default: 10)
545     :submodule-disable: Disable submodule checkout operation.
546         (default: false)
547
548     :gerrit_verify_triggers: Override Gerrit Triggers.
549     :gerrit_trigger_file_paths: Override file paths which can be used to
550         filter which file modifications will trigger a build.
551
552 Maven Verify for Docker
553 -----------------------
554
555 Similar to Maven Verify as described above but logs in to Docker
556 registries first. The project POM file should invoke a plugin to build
557 a Docker image. The base image should be pulled from the registry in
558 the environment variable CONTAINER_PULL_REGISTRY.
559
560 :Template Names:
561
562     - {project-name}-maven-docker-verify-{stream}-{mvn-version}-{java-version}
563     - gerrit-maven-docker-verify
564     - github-maven-docker-verify
565
566 :Required parameters:
567
568     :container-public-registry: Docker registry source with base images.
569
570 All other required and optional parameters are identical to the Maven Verify job
571 described above.
572
573 Maven Verify w/ Dependencies
574 ----------------------------
575
576 Verify job which runs mvn clean install to test a project build /w deps
577
578 This job can be used to verify a patch in conjunction to all of the
579 upstream patches it depends on. The user of this job can provide a list
580 via comment trigger.
581
582 :Template Names:
583
584     - {project-name}-maven-verify-deps-{stream}-{mvn-version}-{java-version}
585     - gerrit-maven-verify-dependencies
586
587 :Comment Trigger: recheck: SPACE_SEPARATED_LIST_OF_PATCHES
588
589 :Required parameters:
590
591     :build-node: The node to run build on.
592     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
593         be configured in defaults.yaml)
594     :mvn-settings: The name of settings file containing credentials for the project.
595
596 :Optional parameters:
597
598     :branch: Git branch to fetch for the build. (default: master)
599     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
600     :build-timeout: Timeout in minutes before aborting build. (default: 60)
601     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
602     :java-version: Version of Java to use for the build. (default: openjdk8)
603     :mvn-global-settings: The name of the Maven global settings to use for
604         Maven configuration. (default: global-settings)
605     :mvn-opts: Sets MAVEN_OPTS. (default: '')
606     :mvn-params: Additional mvn parameters to pass to the cli. (default: '')
607     :mvn-version: Version of maven to use. (default: mvn35)
608     :stream: Keyword that can be used to represent a release code-name.
609         Often the same as the branch. (default: master)
610     :submodule-recursive: Whether to checkout submodules recursively.
611         (default: true)
612     :submodule-timeout: Timeout (in minutes) for checkout operation.
613         (default: 10)
614     :submodule-disable: Disable submodule checkout operation.
615         (default: false)
616
617     :gerrit_verify_triggers: Override Gerrit Triggers.
618     :gerrit_trigger_file_paths: Override file paths which can be used to
619         filter which file modifications will trigger a build.