Running the Maven Release Plugin with Jenkins

12 May

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:

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="" xmlns:xsi="" xsi:schemaLocation="">

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=""

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:
Screen Shot 2014-05-06 at 14.55.44

And in Artifactory it will show the following:
Screen Shot 2014-05-06 at 14.58.48
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:
Screen Shot 2014-05-06 at 16.47.34

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:
Screen Shot 2014-05-06 at 16.56.36

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:
Screen Shot 2014-05-07 at 21.00.45

Now with this plugin in place I get an extra menu option to start your Release Build:
Screen Shot 2014-05-07 at 21.03.17

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:
[INFO] [INFO] ------------------------------------------------------------------------
[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 ( Failed to transfer file: Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
[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] For more information about the errors and possible solutions, please read the following articles:
[INFO] [ERROR] [Help 1]
[INFO] ------------------------------------------------------------------------
[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] 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] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]
[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:
Screen Shot 2014-05-10 at 10.21.03

The final step is to make the Jenkins release build to use this settings.xml file. You can so this like this:
Screen Shot 2014-05-12 at 17.59.55

Now I can run the Maven release build in Jenkins like it runs on my local machine.

2 Responses to “Running the Maven Release Plugin with Jenkins”

  1. karthi4gravatar 27/05/2014 at 15:07 #

    Could I ask you, how do the testers know which revision they deployed on their environment ?
    Thank you,

    • Pascal Alma 27/05/2014 at 19:05 #

      Hi K,

      In our case it are not the testers that deploy the releases but the ‘Operations’ department. So you could ‘solve’ it by setting up a procedure.
      Another more dynamic option would be to create a web page (or in case of Mule ESB a http inbound endpoint) that shows the version + build number of the current deployed release so the testers could easily see what version they are testing against.
      Is that the kind of info you were looking for?

Comments are closed.


Get every new post delivered to your Inbox.

Join 171 other followers

%d bloggers like this: