Plugin Information |
---|
No information for the plugin 'pipeline-maven-plugin' is available. It may have been removed from distribution. |
Introduction
Provides maven integration with Pipeline Plugin by using the withMaven step, which configures a maven environment to use within a pipeline job by calling sh mvn or bat mvn.
Usage
Withn a node or a docker.image block, create a withMaven block to setup a with maven environment. The configured environment will be used when calling maven inside the block by using sh mvn
or bat mvn
. The following parameters can be used to configure maven:
- Maven Installation (
maven
): Allow the selection of a Maven installation configured on the Global Jenkins configuration or on the Global Tool Configuration page if using Jenkins > 2.0. When auto-install is enabled, maven will be downloaded and made available for the pipeline job.
- JDK (
jdk
): Allows the selection of a JDK installation. If auto-install is enabled, the JDK will be downloaded and made available for the pipeline job.
- Maven Settings Config (
mavenSettingsConfig
):* Select a maven settings element from Config File Provider Plugin allowing the replacement of server credentials credentials and variable substitutions as configured in Config File Provider Plugin. The settings element in thesettings.xml
file contains elements used to define values which configure Maven execution in various ways, like thepom.xml
, but should not be bundled to any specific project, or distributed to an audience. See also settings.xml reference
- Maven Settings File Path (
mavenSettingsFilePath
): Specify a mavensettings.xml
file. The specified path can be absolute or relative to the workspace. Shell-like environment variable expansions work in this field, by using the${VARIABLE
} syntax. The file existence is checked on the build agent, if found, that one is used. If not found it will be checked on the master. The settings element in thesettings.xml
file contains elements used to define values which configure Maven execution in various ways, like thepom.xml
, but should not be bundled to any specific project, or distributed to an audience. These include values such as the local repository location, alternate remote repository servers, and authentication information.
There are two locations where asettings.xml
file per default may live:- The Maven install - default:
$M2_HOME/conf/settings.xml
- A user's install - default:
${user.home}/.m2/settings.xml
The formersettings.xml
are also called global settings, the lattersettings.xml
are referred to as user settings. If both files exists, their contents gets merged, with the user-specificsettings.xml
being dominant.
- The Maven install - default:
- Maven JVM Opts (
mavenOpts
): Specify JVM specific options needed when launching Maven as an external process, these are not maven specific options. See: Java Options
Shell-like environment variable expansions work in this field, by using the${VARIABLE
} syntax.
- Maven Local Repository (
mavenLocalRepo
): Specify a custom local repository path. Shell-like environment variable expansions work with this field, by using the${VARIABLE
} syntax. Normally, Jenkins uses the local Maven repository as determined by Maven, by default~/.m2/repository
and can be overridden by<localRepository>
in~/.m2/settings.xml
(see Configuring your Local Repository))
This normally means that all the jobs that are executed on the same node shares a single Maven repository. The upside of this is that you can save the disk space, the downside is that the repository is not multi process safe and having multiple builds run concurrently can corrupt it. Additionally builds could interfere with each other by sharing incorrect or partially built artifacts. For example, you might end up having builds incorrectly succeed, just because your have all the dependencies in your local repository, despite that fact that none of the repositories in POM might have them.
By using this option, Jenkins will tell Maven to use a custom path for the build as the local Maven repository by using-Dmaven.repo.local
ie.$WORKSPACE/.repository
if.repository
value is specified.
The Pipeline Syntax snippet code generator can be used to assist on generating the withMaven step parameters
An example pipeline script using the plugin would be:
node{ // Mark the code checkout 'stage'.... stage 'Checkout' // Get some code from a GitHub repository git url: 'https://github.com/alvarolobato/maven_test.git' // Mark the code build stage 'Build' withMaven(maven: 'M3', mavenLocalRepo: '.repository', mavenSettingsConfig: 'maven-settings-for-gameoflife') { // Run the maven build sh "mvn clean install" } }
In the above example the following parameters are use to configure maven:
- maven: 'M3' Maven Installation will be used, this installation has to be declared in the Global Jenkins configuration or Tool installations page.
- mavenLocalRepo: a local repository folder is specified to avoid shared repositories
- mavenSettingsConfig: specifies an specific settings.xml configuration from Config File Provider Plugin plugin, allowing the replacement of variables and credentials.
Known Limitations
Maven Installation and JDK parameters do not work with docker.image('xxx').inside as the docker step does not allow the use of Tool Installer, the preinstalled Maven and JDK on the docker image will be auto-discovered and used.
Changelog
0.2
- First stable release
- JENKINS-37613 - Unify naming convention for tool installation. The
mavenInstallation
parameter was renamed tomaven
.
0.1-beta
- Initial version