OK, So here’s a quick tutorial on how to make a Jenkins and Maven Release plugin build that automatically creates a release build using Jenkins and we are assuming your code is in Git.
Step 1 is easy, get your code from Git. You just configure the Jenkins build as always.
Now, We need one additional plugin for Jenkins which is “Workspace Cleanup Plugin”. This allows us to enable
“Delete workspace before build starts” in Build Environment section.
Now the tricky part: Under Pre Steps you must add a new shell command:
git checkout master
This is because otherwise your git is checked out without a specific branch and maven release plugin will fail.
-B -Dusername=jenkins -Dpassword=JenkinsPasswordForGit release:prepare release:perform
Important notice – you can configure jenkins user to have automatic access to git in other ways also, but I decided to keep this info in the build.
Once you start releasing your project with Jenkins, you quickly discover that manually managing the version numbers inside your own multi-module project will become a hassle. Simple solution would be to configure Jenkins to upgrade your own dependencies to the latest releases (requires you to limit versions plugin to your own packages):
-B versions:use-latest-releases scm:checkin -Dmessage=$BUILD_NUMBER -Dusername=jenkins -Dpassword=JenkinsPasswordForGit release:prepare release:perform
Now we might want to limit versions plugin to our own com.codeyouneed package since having it upgrade ALL dependencies all the time is really bad.
Now that’s pretty much it. That git checkout master command took me a while to figure out.
Of course, for maven release plugin to work you actually need to add some stuff to your pom.xml also:
Important notice if you are dealing with multi-module maven projects – Submodules have to leave out their name from scm.url since release plugin will add the name by itself into the end of the URL.
So you should leave out the “/submodulename”.
Special thanks to a blog post that lead me to the right path: http://labs.bsb.com/2014/02/better-maven-releases-with-jenkins/