Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Plugin Information

View Pipeline Maven Integration on the plugin site for more information.

Older versions of this plugin may not be safe to use. Please review the following warnings before using an older version:

This plugin is still work in progress, no releases yet.
 
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.

UsageWithn 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 (mavenInstallation): 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 the settings.xml file contains elements used to define values which configure Maven execution in various ways, like the pom.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 maven settings.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 the settings.xml file contains elements used to define values which configure Maven execution in various ways, like the pom.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 a settings.xml file per default may live:
The Maven install - default: $M2_HOME/conf/settings.xmlA user's install - default: $

Unknown macro: {user.home}

/.m2/settings.xmlThe former settings.xml are also called global settings, the latter settings.xml are referred to as user settings. If both files exists, their contents gets merged, with the user-specific settings.xml being dominant.
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.
 
This means each job could get its own isolated Maven repository just for itself. It fixes the above problems, at the expense of additional disk space consumption.When using this option, consider setting up a Maven artifact manager so that you don't have to hit remote Maven repositories too often. 

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 repositorygit url: 'https://github.com/alvarolobato/maven_test.git'// Mark the code buildstage 'Build' withMaven(mavenInstallation: 'M3', mavenLocalRepo: '.repository', mavenSettingsConfig: 'maven-settings-for-gameoflife')

Unknown macro: {// Run the maven buildsh"mvn clean install"}

}In the above example the following parameters are use to configure maven:
 
mavenInstallation: '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 repositoriesmavenSettingsConfig: specifies an specific settings.xml configuration from File Configuration Provider plugin, allowing the replacement of variables and credentials.Known LimitationsMaven 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. 
 
 

  • No labels