Running the Maven Release Plugin with Jenkins
Learn more about using the Maven Release plugin on Jenkins, including subversion source control, artifactory, continuous integration, and more.
Join the DZone community and get the full member experience.
Join For Free
recently i started to implement our release process in
jenkins
. until then i just ran
the release plugin
of
maven
on my local machine which did the job. as i said we decided to move this task to jenkins. the build/release toolstack was:
- subversion as source control
- artifactory as internal maven repository
- jenkins for continious integration
- java source code as maven projects
to show my jenkins configuration i have setup a very basic maven module named ‘myapp’ with the following pom:
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelversion>4.0.0</modelversion>
<groupid>net.pascalalma.demo</groupid>
<artifactid>myapp</artifactid>
<packaging>pom</packaging>
<version>1.0.1-snapshot</version>
<name>${project.artifactid}</name>
<properties>
<jdk.version>1.7</jdk.version>
</properties>
<build>
<plugins>
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-compiler-plugin</artifactid>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceencoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-release-plugin</artifactid>
<version>2.4.2</version>
</plugin>
</plugins>
</build>
<scm>
<developerconnection>scm:svn:https://svn.4synergy.nl/sandbox/myapp/trunk</developerconnection>
</scm>
<distributionmanagement>
<repository>
<id>ec2-arti</id>
<url>http://artifactory.4synergy.nl/artifactory/libs-release-local</url>
</repository>
<snapshotrepository>
<id>ec2-arti</id>
<url>http://artifactory.4synergy.nl/artifactory/libs-snapshot-local</url>
</snapshotrepository>
</distributionmanagement>
</project>
as you can see not much special here: i have included the release plugin of maven, the scm developers connection so it can check-in and out the code of the svn repository and artifactory as repositories to deploy to.
and of course not to forget the following maven settings file:
<?xml version="1.0" encoding="utf-8"?>
<settings xmlns="http://maven.apache.org/settings/1.0.0"
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
xsi:schemalocation="http://maven.apache.org/settings/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<username>admin</username>
<password>password</password>
<id>ec2-arti</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorof>*</mirrorof>
<name>remote-repos</name>
<url>http://artifactory.4synergy.nl/artifactory/remote-repos</url>
<id>remote-repos</id>
</mirror>
</mirrors>
</settings>
with this setup i can run the maven release plugin locally like this:
mvn -b release:clean release:prepare release:perform
this will do all the stuff the maven release plugin should do and results in svn with the following structure:
and in artifactory it will show the following:
so that works. now let me show you what steps i needed to make it work on a separated jenkins server.
with the following config in jenkins i can check-out and build my maven module:
the next step is to run the release plugin of maven. for this i use
the following jenkins plugin
that i added to the jenkins configuration:
after installing this plugin you can configure the maven release plugin in your module configuration. it will generate some extra options in the module configuration:
now with this plugin in place i get an extra menu option to start your release build:
after i made sure the os user that is running jenkins could execute svn on the jenkins server and had access to the svn repository i ran into the following issue:
[info] [info] uploading: http://54.216.254.98/artifactory/libs-release-local/net/pascalalma/demo/myapp/1.0.3/myapp-1.0.3.pom
[info] [info] ------------------------------------------------------------------------
[info] [info] build failure
[info] [info] ------------------------------------------------------------------------
[info] [info] total time: 40.501 s
[info] [info] finished at: 2014-05-07t18:45:13+00:00
[info] [info] final memory: 12m/30m
[info] [info] ------------------------------------------------------------------------
[info] [error] failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project myapp: failed to deploy artifacts: could not transfer artifact net.pascalalma.demo:myapp:pom:1.0.3 from/to ec2-arti (http://54.216.254.98/artifactory/libs-release-local): failed to transfer file: http://54.216.254.98/artifactory/libs-release-local/net/pascalalma/demo/myapp/1.0.3/myapp-1.0.3.pom. return code is: 401, reasonphrase: unauthorized. -> [help 1]
[info] [error]
[info] [error] to see the full stack trace of the errors, re-run maven with the -e switch.
[info] [error] re-run maven using the -x switch to enable full debug logging.
[info] [error]
[info] [error] for more information about the errors and possible solutions, please read the following articles:
[info] [error] [help 1] http://cwiki.apache.org/confluence/display/maven/mojoexecutionexception
[info] ------------------------------------------------------------------------
[info] build failure
[info] ------------------------------------------------------------------------
[info] total time: 02:05 min
[info] finished at: 2014-05-07t18:45:14+00:00
[info] final memory: 9m/21m
[info] ------------------------------------------------------------------------
[error] failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:perform (default-cli) on project myapp: maven execution failed, exit code: '1' -> [help 1]
[error]
[error] to see the full stack trace of the errors, re-run maven with the -e switch.
[error] re-run maven using the -x switch to enable full debug logging.
[error]
[error] for more information about the errors and possible solutions, please read the following articles:
[error] [help 1] http://cwiki.apache.org/confluence/display/maven/mojoexecutionexception
[jenkins] archiving /opt/bitnami/apps/jenkins/jenkins_home/jobs/my-app/workspace/pom.xml to net.pascalalma.demo/myapp/1.0.3-snapshot/myapp-1.0.3-snapshot.pom
channel stopped
finished: failure
in my local environment i have defined the necessary username and pasword for the artifactory instance in my maven settings.xml but it is missing this info when running the maven job in jenkins. now we can add this settings.xml also to the user running jenkins and see if that works but a cleaner approach is to use a plugin for this. in this case the
config fileprovider plugin
. after adding this plugin to jenkins you can define any config file in it, in our case a maven settings.xml file:
the final step is to make the jenkins release build to use this settings.xml file. you can so this like this:
now i can run the maven release build in jenkins like it runs on my local machine.
Published at DZone with permission of $$anonymous$$. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments