11

We are using the standard git flow branching model (develop, master, release-, hotfix-, etc).

As part of our workflow, we would like to set up a "one-click" release via jenkins.

I was looking at the jgitflow-maven-plugin. Can I set up this plugin to do a one-click release from jenkins? If so, what are the configuration options?

In particular, can I do something like this?

Jenkins Job
Maven goals:    release-start release-finish -Dsomething -Delse

And is there a way tell it to automatically build from the latest -SNAPSHOT version, e.g. if the version is 1.2.3-SNAPSHOT it would build release-1.2.3.

Otherwise, is there a maven plugin that builds releases according the git flow branching model (i.e. build from develop and create a new release branch named release-x.y.z).

vikingsteve
  • 38,481
  • 23
  • 112
  • 156
  • Did you manage it in the meantime? if yes, how? – Puce Jun 03 '15 at 14:40
  • No, we didn't get it working yet. Still doing mvn release:prepare and release:perform (which, as we all know, is a royal pain in the b**t). – vikingsteve Jun 03 '15 at 17:38
  • 1
    Just a little update here, we are working with a unix script named `release.sh` which does the following: `git flow release start ...`, `mvn -B release:prepare`, `mvn release:perform`, `git flow release finish ...`. It's not ideal, and it doesnt work from windows machines, but it's the best solution we have right now. – vikingsteve Jan 25 '16 at 18:31
  • Hi I'm working on the similar stuff at the moment, I tried 'gitflow-maven-plugin' , basic you can update the version with a single command (still not completely automate though) and I'm still figuring how to combine this with Jenkins, just wondering if you managed to get it work? – wawawa Nov 23 '19 at 16:57

4 Answers4

13

Although this answer is one year old I'd like point out that meanwhile the jgitflow (v1.0-m5.1) works with maven batch mode.

So to release an artifact with just one command you can execute:

mvn --batch-mode jgitflow:release-start jgitflow:release-finish

You don't need to set developmentVersion and releaseVersion.

JGitFlow will use the current version minus the -SNAPSHOT part as release version. Then it increments the least significant digit and adds -SNAPSHOT again for the next development version.
Example 1.0.0-SNAPSHOT --> Release: 1.0.0, next Development version: 1.0.1-SNAPSHOT

In order to configure a single click Jenkins release job you need to configure some things regarding Git.

Under Source Code Management > Git > Additional Behaviors select

  • Wipe out repository & force git clone: just to make sure the workspace is clean
  • Checkout to specific local branch: your develop branch.

Finally, the release happens locally on your Jenkins server, so you want to push back the changes to your Git remote server.

To accomplish this, the easiest way is to add a Post-build action which executes the following bash command (the branch names may vary, I've used the JGitFlow default values):

git push origin develop master --tags

Note If Jenkins is running on Windows you either have to execute a Batch script containing the same command (sometimes this doesn't work due to SSH issues with Windows) or configure the Git Publisher Post-build action accordingly.

gucce
  • 597
  • 4
  • 12
  • Looks promising, Ill test this out. Thank you. – vikingsteve Aug 19 '16 at 10:41
  • Basically, it comes down to these four commands packaged as Jenkins job: `git clone . && git checkout develop && mvn --batch-mode jgitflow:release-start jgitflow:release-finish && git push origin develop master --tags ` – gucce Aug 22 '16 at 12:20
  • 1
    @gucce your steps worked great. Given that jgitflow hasn't seen active development in a while, have you had success with any other git flow maven plugins? – testphreak Oct 06 '16 at 23:09
  • @testphreak No, I'm not aware of any other maven plugins. Although it is not under active development (and maybe never will be again, see [1]), we have not encountered any problems preventing us from using it for our current project. For the next project I don't know if we'll use it again. [1] https://groups.google.com/forum/#!topic/maven-jgitflow-users/NeVNHqD7a8w – gucce Oct 13 '16 at 12:03
  • 1
    Just wanted to point out you don't need to add the push command, there is a paramter for that: -DpushReleases=true. We use this and it makes the jenkins job dead simple. https://bitbucket.org/atlassian/jgit-flow/wiki/goals/release-start#!pushreleases – Noremac Dec 01 '16 at 19:22
  • I used 'gitflow-maven-plugin' to update the versioning instead of 'jgitflow-maven-plugin', just wonderin what's the difference between them? I assume we can only configure and work with Jenkins via 'jgitflow-maven-plugin' instead of ''gitflow-maven-plugin'? – wawawa Nov 23 '19 at 17:03
  • 'Under Source Code Management > Git' Is it in Jenkins platform? Or IntelliJ? – wawawa Nov 27 '19 at 11:29
  • @Cecilia Jenkins, of course. No one said anything about IntelliJ on this page. – gucce Nov 28 '19 at 13:44
  • I didn't find this configuration in my Jenkins, is it possible that I don't have the valid privilege to do so? @gucce – wawawa Nov 28 '19 at 13:47
1

You can simply use the jenkins plugin M2 Release Plugin with the release goals an options -B -DautoVersionSubmodules=true jgitflow:release-start jgitflow:release-finish

CSchulz
  • 10,882
  • 11
  • 60
  • 114
dimapin
  • 11
  • 1
1

We ended up with starting the release via CLI on the client (because in Jenkins there is a bug starting the release).

git flow release start -DautoVersionSubmodules=true

If you want to use the batch mode you need to specify developmentVersion and releaseVersion.

Created a new job in Jenkins to build the release branch and use the M2 Release Plugin to release it finally:

-B jgitflow:release-finish

If you use some custom profiles, you have to pass them additional via arguments caused by a bug.

-Darguments=-Pprofile
CSchulz
  • 10,882
  • 11
  • 60
  • 114
0

We never found a way to get this to work via a plugin or maven goal in Jenkins.

Our solution ended up with a bash script that did git flow release start <version>, maven release process, git flow release finish <version> and other things (git pull on develop and master at very start, git push and slack notification at very end).

vikingsteve
  • 38,481
  • 23
  • 112
  • 156