mardi 28 février 2012

Release your product with cloudbees/git/github and maven (of course)

  • Intro

We needed to be able to release a version of our product in the following context:
-a release each sprint (2 weeks) if we did some modification into the product
-CI = Jenkins & Maven @ CloudBees + git @ GitHub

We wanted to release each sprint and because we are lazy developer, we would like to have an industrial process to do new release with a simple "clic button release" feature. We know that we are able to create a fresh new release "manually" using maven with somes edition and some command but you know: the less human do things manually, the less bug you have, the more you script, the more you can reproduce it easily and frequently. And having a industrial process doesn't force us to use it, if we need to use another workflow for a specific release, we can choose to do the release manually. But most of the time we should use the industrial process...

This may seems easy for you, but since I don't want to forget how I did it, I script it... ugh... I blog it.

Here is a set of article explaining how to use the maven release plugin and what is the process a release:

But in our context, here is what we should do :

  • Configure your pom

First you have to change your pom.xml since the release plugin has some requirement.

Add a scm config:
<scm>
<developerConnection>scm:git:ssh://git@github.com/geek4ever/kickass.git</developerConnection>
<connection>scm:git:ssh://git@github.com/geek4ever/kickass.git</connection>
<url>git:ssh://git@github.com/geek4ever/kickass.git</url>
</scm>
Be careful, your githubb scm url must be ssh://git@github.com/geek4ever and not ssh://git@github.com:geek4ever or you will face a limitation of the maven git scm plugin. Because when you use ":", the plugin think the word just after (eg: geek4ever)is the port to use to connect to the host.

Add a distribution management config:
 <distributionManagement>
<downloadUrl>https://github.com/geek4ever/kickass</downloadUrl>
<repository>
<id>geek4ever-cloudbees-release</id>
<name>geek4ever-cloudbees-release</name>
<url>dav:https://repository-geek4ever.forge.cloudbees.com/release/</url>
</repository>
<snapshotRepository>
<id>geek4ever-cloudbees-snapshot</id>
<name>geek4ever-cloudbees-snapshot</name>
<url>dav:https://repository-geek4ever.forge.cloudbees.com/snapshot/</url>
</snapshotRepository>
</distributionManagement>
Be careful, don't forget the "dav:" prefix in your url or you will face a problem when trying to deploy your artifact, because cloudbees repositories are available only with webdav.

Add an extension to your build to be able to deploy on a webdav repository:
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>2.2</version>
</extension>
</extensions>
...
</build>
You can try wagon-webdav if you face problem with wagon-webdav-jackrabbit

Of course you add the release plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
</plugin>
Add your repositories:
      <repository>
<id>geek4ever-cloudbees-snapshot</id>
<name>geek4ever-cloudbees-snapshot</name>
<url>https://repository-geek4ever.forge.cloudbees.com/snapshot/</url>
</repository>
<repository>
<id>geek4ever-cloudbees-release</id>
<name>geek4ever-cloudbees-release</name>
<url>https://repository-geek4ever.forge.cloudbees.com/release/</url>
</repository>
Now, your pom config is ready and you can release your project using the maven release plugin with these command:
mvn release:prepare -DdryRun=true #until BUILD SUCCESSFULL
mvn release:prepare
mvn release:perform

  • Configure Jenkins:

Next step is to configure jenkins to be able to release with a simple click button:

You need to install M2 Release Plugin on jenkins:

On Cloudbees to install a plugin, it is pretty easy with in the administration screen.

Then you need to setup a specific settings.xml for your jenkins because to be able to deploy on the repositories, maven need to know your credentials to access to the repositories:
<servers>
<server>
<id>geek4ever-cloudbees-snapshot</id>
<username>jenkins</username>
<password>pass;-)word</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
<server>
<id>geek4ever-cloudbees-release</id>
<username>jenkins</username>
<password>pass;-)word</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
</server>
<server>
<id>cloudbees-private-repository</id>
<username>jenkins</username>
<password>pass;-)word</password>
</server>
<server>
<id>cloudbees-private-snapshot-repository</id>
<username>jenkins</username>
<password>pass;-)word</password>
</server>
</servers>
cloudbees-private-repository and cloudbees-private-snapshot-repository are 2 repositories that jenkins use to deploy your release/snapshot artifacts.
geek4ever-cloudbees-snapshot and geek4ever-cloudbees-release are 2 repositories we used in our pom.xml to deploy your release/snapshot artifacts.
You should add this settings.xml in your private cloudbees repository: https://repository-webadeo.forge.cloudbees.com/private/settings.xml

To connect to this repository you can use a cloudbees account (login/pass = jenkins/pass;-)word in our exemple)
  • Configure your jenkins build
In the configuration of your build:

-In Build section, click on Advanced button to check "Fichier settings alternatif" and set this value: /private/geek4ever/settings.xml where geek4ever is your account
(WARNING: You will have an error message "Alternate settings file must be a relative path." but do not care of this message)

-Check "Maven release build"

-Use "clean deploy" as goal to launch

-Use maven 3.0.4 (3.0.3 was buggy with webdav deploy)

  • Perform a release
Click on "Perform Maven Release", configure your version, look at the logs to wait the end of the build, then enjoy ^^

1 commentaire:

  1. I definitely wanted to compose a small remark to appreciate you for those precious tips you are writing at this website. Sepeda Motor Bebek Injeksi Kencang dan Irit Jupiter Z1

    RépondreSupprimer