Automatic Install of Maven with Jenkins and use within Pipeline
Assume you want a specific version of Maven to be installed automatically when doing a build e.g because you need to have a build executed on a remote node.
This is what you need to do to perform this :
This is what you need to do to perform this :
- Install the following 2 plugins on your Jenkins 2x instance ( if not already preseent :
- Config File Provider - https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin
- Pipeline Maven Plugin - https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Maven+Plugin
- Restart your Jenkins such as the Plugins can take effect
- Define your settings.xml file within Jenkins > Manage Jenkins > Managed Files
- Click on Add a new Config
- choose Global Maven settings
- choose a valid id name e.g GlobalMavenSettingsForXXX
- copy paste the settings.xml of your project on next page
- Note the settings.xml should allow you to get your plugins and dependencies from your repositories
- Define your Maven tool within the menu Jenkins > Manage Jenkins > Global Tool Configuration page
- Click on Maven Installations
- Specify name for your maven
- Specify maven home directory e.g /usr/local/maven-3.2.5
- Check the Automatic install option
- Choose Install from Apache e.g maven-3.2.5
- Make sure that you Jenkins has access to install Maven within your maven home directory by executing the following command (on your slave ):
- sudo chmod -R ugo+rw /usr/local/maven-3.2.5
- Now you can use maven in your Jenkins pipeline using a command such as :
withMaven(globalMavenSettingsConfig: 'maven-atlas-global-settings', jdk: 'JDK6', maven: 'M3_3.2.5', mavenLocalRepo: '/home/ubuntu/.m2/repository/') {
sh 'mvn clean install '
}
Note that you can use the Pipeline Syntax helper to fill the options you want to use with Maven .
No comments:
Post a Comment