Maven Release Plugin Horrors with git

If you have spent any time trying to use the Maven release plugin, you probably hate it.  It wants to run your build twice, typically you have to wait 20 minutes to hours depending on the size of your project to figure out that it barfed and then try something else, barf again.  At some point you either dig in really hard, or start looking for other solutions.

As is just about typical with every major block I have, just when I’m about to kill myself, my dog, or anyone that comes near me, I figure things out.

So my story is this, we have the Maven release plugin working great locally, but doing releases from laptops is not ideal, and of course on the weekend I needed to do a release and the VPN was painful to run the test suite over.  I decided it was about time to get this thing working in jenkins, how hard could it be, throw it up there, wire in the maven goals, bada bing right ?

Not so much.

Ran the release goals, everything is awesome, then it goes to push the thing back into git:


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.2:prepare (default-cli)
on project trax-platform: An error is occurred in the checkin process: Exception while executing SCM command.
Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref -> [Help 1]

view raw

gistfile1.txt

hosted with ❤ by GitHub

I do some googling, find out that jenkins checks out git code into a detached head, so you need to deal with that.  After a few failed attempts doing things that seemed much more complicated then they needed to be I landed on this:

http://stackoverflow.com/questions/11511390/jenkins-git-plugin-detached-head

Basically you need to just pick the “check out to specific local branch” option and set your branch.  Grab a beer, wait another 25 minutes and then bamn!:


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.2:prepare (default-cli) on project trax-platform: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] fatal: could not read Username for 'https://github.com': No such device or address
[ERROR] -> [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.

view raw

gistfile1.txt

hosted with ❤ by GitHub

Well this one got got me stuck forever.  Convinced it was some credential problem in jenkins trying all sorts of things messing around with the git plugin, credentials, you name it nothing helping.  Started pondering on “this is why people hate Java”…

Then finally I was sitting there staring at that url,

could not read Username for 'https://github.com'

Thinking about where have I seen that before somewhere else.  Oh yeah, its in the maven pom.xml:


<scm>
<developerConnection>scm:git:https://github.com/TraxTechnologies/PlatformComponents/</developerConnection&gt;
<tag>HEAD</tag>
</scm>

view raw

gistfile1.txt

hosted with ❤ by GitHub

I changed the git url to this:


<scm>
<developerConnection>scm:git:git@github.com:TraxTechnologies/PlatformComponents.git</developerConnection>
<tag>HEAD</tag>
</scm>

view raw

gistfile1.txt

hosted with ❤ by GitHub

And hell yeah it finally worked.  It makes sense if you think about how git is handling security that the http protocol isn’t going to work here since since we are detached from the original git pull of the code.  Anyway, it was much pain and suffering and I couldn’t believe stackoverflow and google let me down, it took way too much time to figure this out.  That is why I’m blogging about it, so some other poor sorry soul won’t have to kill their dog over it.

As a side note, I ran into this while looking for a solution:

http://axelfontaine.com/blog/final-nail.html

This guys approach seems pretty interesting.  It eliminates the two builds and seems really simple and straightforward to implement.  I was just about to try it out, when I got the past this.  But for sure when I find some time, or next time this poops out, I might be giving that a go.

For the record, I have other builds using the SBT release plugin, and I went really deep on that too, I have battle scars from that one too, a tail for another day…

4 thoughts on “Maven Release Plugin Horrors with git

  1. downdrown says:

    Ran into the same problem today… My only problem is that I am forced to push changes via https, since ssh is blocked! The only way I was able to get this thing working was adding the github credentials directly into the plugin configuration, which is not a very pretty solution! Is it possible to pass these credentials through the maven’s settings.xml?

  2. downdrown says:

    Nevermind – had a bad configuration tag in my settings.xml – was actually pretty easy, using a tag! Anyway thank you for documenting this workflow! Best regards

Leave a comment