112

I get the following error output while running the Maven release plugin prepare step i.e. mvn release:prepare --batch-mode -DreleaseVersion=1.1.2 -DdevelopmentVersion=1.2.0-SNAPSHOT -Dtag=v1.1.2 -X from an Atlassian Bamboo plan. However doing the same in the command line works fine. The full error stack is below.

Any ideas how can this be solved?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:prepare (default-cli) on project hpcmom: 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]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:prepare (default-cli) on project hpcmom: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.plugins.release.PrepareReleaseMojo.prepareRelease(PrepareReleaseMojo.java:281)
    at org.apache.maven.plugins.release.PrepareReleaseMojo.execute(PrepareReleaseMojo.java:232)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: org.apache.maven.shared.release.ReleaseExecutionException: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.checkin(AbstractScmCommitPhase.java:160)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.performCheckins(AbstractScmCommitPhase.java:145)
    at org.apache.maven.shared.release.phase.ScmCommitPreparationPhase.runLogic(ScmCommitPreparationPhase.java:76)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.execute(AbstractScmCommitPhase.java:78)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:234)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:169)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:146)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:107)
    at org.apache.maven.plugins.release.PrepareReleaseMojo.prepareRelease(PrepareReleaseMojo.java:277)
    ... 22 more
Caused by: org.apache.maven.scm.ScmException: Exception while executing SCM command.
    at org.apache.maven.scm.command.AbstractCommand.execute(AbstractCommand.java:63)
    at org.apache.maven.scm.provider.git.AbstractGitScmProvider.executeCommand(AbstractGitScmProvider.java:291)
    at org.apache.maven.scm.provider.git.AbstractGitScmProvider.checkin(AbstractGitScmProvider.java:217)
    at org.apache.maven.scm.provider.AbstractScmProvider.checkIn(AbstractScmProvider.java:410)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.checkin(AbstractScmCommitPhase.java:156)
    ... 30 more
Caused by: org.apache.maven.scm.ScmException: Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref

    at org.apache.maven.scm.provider.git.gitexe.command.branch.GitBranchCommand.getCurrentBranch(GitBranchCommand.java:147)
    at org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand.createPushCommandLine(GitCheckInCommand.java:192)
    at org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand.executeCheckInCommand(GitCheckInCommand.java:132)
    at org.apache.maven.scm.command.checkin.AbstractCheckInCommand.executeCommand(AbstractCheckInCommand.java:54)
    at org.apache.maven.scm.command.AbstractCommand.execute(AbstractCommand.java:59)
    ... 34 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
simple  02-Dec-2013 17:18:09    Failing task since return code of [/opt/dev/apache-maven/3.0.5//bin/mvn -Djava.io.tmpdir=/opt/atlassian/bamboo/5.2.1/temp/HPCMOM-RELEASE-JOB1 release:prepare --batch-mode -DignoreSnapshots=false -DreleaseVersion=1.1.2 -DdevelopmentVersion=1.2.0-SNAPSHOT -Dtag=v1.1.2 -X] was 1 while expected 0

UPDATE:

Doing git ls-remote . on a local workspace clone produces:

azg@olympus:~/code/hpcmom$ git ls-remote .
7894eea08a0afecb99515d1339623be63a7539d4    HEAD
7894eea08a0afecb99515d1339623be63a7539d4    refs/heads/master
7894eea08a0afecb99515d1339623be63a7539d4    refs/remotes/origin/HEAD
7894eea08a0afecb99515d1339623be63a7539d4    refs/remotes/origin/master
6a7095b86cccdfd4b28e4dea633d0930809ae9ac    refs/tags/v1.0
1a53462b1ecf0abfea8245016304cda9c78b420d    refs/tags/v1.0^{}
5113a7cbcf35c47b680a9c36e15e5fa01ef1d2e6    refs/tags/v1.1
79a3073ecabe65d3c8051520f8007d9e49a65a06    refs/tags/v1.1^{}
a00249209597ea1214d80ee38f228c40db7022c2    refs/tags/v1.1.0
e892bce8d25d87368ab557fee0d30810bef7e31e    refs/tags/v1.1.0^{}
b491a312c39088533cb069e4ab1ae8a00d1f6bfe    refs/tags/v1.1.2
a3f7618dada7ed60d8190426152ffd90e0e40a86    refs/tags/v1.1.2^{}

Doing git ls-remote . on the Bamboo clone produces:

azg@olympus:/var/atlassian/application-data/bamboo/xml-data/build-dir/HPCMOM-RELEASE-JOB1$ git ls-remote .
2422ce066ac35dae3c54f1435ef8dae5008a9a14    HEAD
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/heads/master
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/remotes/origin/HEAD
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/remotes/origin/master
7539f9700d78a1b766fca7ed9f409914f1ea9d08    refs/tags/vnull
6bfa8c3fdb1f8f56a385035f01b1b77b6e88da8b    refs/tags/vnull^{}

and this is very weird why is the local development clone output so different from the Bamboo one?

SkyWalker
  • 11,704
  • 14
  • 65
  • 144
  • 4
    Okay, so the issue here is that the checkout under Bamboo is in a "detached HEAD" state. It appears that Maven is trying to parse the current branch name and fails because in the detached HEAD state, the `HEAD` ref no longer refers to a branch name, but a SHA1. You can simulate this locally by running `git checkout SHA1` or appending `^{}` to the name of a ref: `git checkout HEAD^{}`. It looks like the Bamboo git plugin attempts to checkout the branch, if at all possible. So it appears you have a race: before the build runs, new stuff has shown up. It's not clear to me yet how to fix it. – John Szakmeister Dec 04 '13 at 11:48
  • Possible duplicate of [Active Git branch is "(no branch)" on hudson CI](http://stackoverflow.com/questions/3858563/active-git-branch-is-no-branch-on-hudson-ci) – Alberto Feb 26 '16 at 13:56

10 Answers10

161

I ran into the same error on Jenkins in combination with maven release plugin, we fixed it by going to Additional behaviours, Check out to specific local branch and enter 'master'

I realise this is not a solution but it might give you some direction in where to look.

jvwilge
  • 2,239
  • 2
  • 13
  • 20
  • 5
    It works when you are building from master branch. If your branch is different, even after changing it to specific branch name, it doesn't work. – siddhusingh Aug 05 '14 at 10:57
  • 30
    I'm on a different branch than master and it works too. I think the problem is that the jenkins git plugin normally checks out the branch in detached head state. So the `git symbolic-ref` command fails. By adding `Check out to specific local branch` we fix this. – René Link Oct 07 '14 at 11:38
  • 20
    Using `**` instead of `master` will match the local branch name to the remote one. – neXus May 02 '17 at 15:07
  • 2
    According to help ([Git Plugin - Jenkins - Jenkins Wiki](https://wiki.jenkins.io/display/JENKINS/Git+Plugin#GitPlugin-AdvancedFeatures)), leaving the field empty can work for this, too: "If selected, and its value is an empty string or `**`, then the branch name is computed from the remote branch without the origin." – evgeny9 Aug 14 '19 at 12:39
  • @jvwilge In my case, it's a shared pipeline, so all settings are coming from pom.xml. how do I write in the code this instruction: Additional behaviors, Check out to specific local branch and enter 'master' – arielma Jan 01 '20 at 07:45
36

For Jenkins and GIT add the additional behaviour check out to specific local branch and use the Workspace Cleanup Plugin to clean your workspace to the beginning of your CI job.

toschneck
  • 630
  • 6
  • 10
  • 1
    thanks, this worked for me. I needed to add ``-Darguments="-Dmaven.deploy.skip=true"``, too. – timbru31 Sep 08 '15 at 20:10
  • @toschneck Hi I am having this exact issue using Jenkins and Git. Could you please expand your answer here to include the commands and config for the plugin you mentioned. Thanks. – Jeremy Feb 23 '16 at 09:04
  • What is the reason to additionally clean the workspace? – kap Nov 17 '16 at 12:59
  • Currently I moved further to the maven-jgitflow plugin. It supports feature and bugfix branching and have the best release functionality I have seen. https://bitbucket.org/atlassian/jgit-flow/wiki/Home – toschneck Dec 27 '16 at 08:25
  • Adding "check out to specific local branch" works for me too. – johnlinp Mar 26 '20 at 05:17
12

The problem in Atlassian Bamboo was solved by un-checking the default setting Use shallow clones with description Fetches the shallowest commit history possible. Do not use if your build depends on full repository history. This checkbox is located under Plan Configuration -> Repositories tab -> Git -> Advanced options

After this all the releases work fine.

SkyWalker
  • 11,704
  • 14
  • 65
  • 144
5

Unchecking the Use shallow clones was not sufficient in my case (I'm using Bamboo 5.7.2). I needed to also enable Force Clean Build in the Source Code Checkout task. Enabling the Use shallow clones would work for the next execution of the job, but all subsequent execution would result in the same error.

Jean Marois
  • 1,362
  • 10
  • 17
5

I am using a Jenkins Team Project with a Multibranch Project Setup.

I previously used checkout scm command.

Now I am using the following code:

checkout([
                 $class: 'GitSCM',
                 branches: scm.branches,
                 extensions: scm.extensions + [[$class: 'CleanCheckout'], [$class: 'LocalBranch', localBranch: 'new']],
                 userRemoteConfigs: scm.userRemoteConfigs
            ])
kevcodez
  • 1,121
  • 10
  • 25
  • 2
    Gave this an upvote since it seemed to do the trick. But after some more tinkering, I noticed that it actually created a new branch called "new" (when using with maven release plugin). A more correct approach would be to change `new` with `**`, which makes the local branch name the same as the remote. – Tobb Jan 28 '20 at 22:47
4

I have seen this problem under Bamboo used with Maven Release plug-in. I've fixed it by enabling the option 'Force Clean Build' in the 'Source Checkout' task. Bamboo says this might make the build slower, but it works and I didn't seen any significant time increase.

zakmck
  • 2,022
  • 27
  • 37
4

what worked for me was to call "git checkout -f master" before calling "mvn release"

Vincent F
  • 4,049
  • 5
  • 22
  • 48
3

For GitHub actions you can setup actions/checkout@v2 with ref: master

steps:
  - uses: actions/checkout@v2
    with:
      ref: master
RecuencoJones
  • 2,342
  • 3
  • 16
  • 21
0

For us the issue was with maven version specified in the pom file. Corrected the maven version specified in the pom file in accordance with the one in bamboo fixed the issue

Manu
  • 2,798
  • 2
  • 22
  • 24
0

The problem is that it is not picking up the branch so before doing mvn release:prepare --batch-mode -DreleaseVersion=1.1.2 -DdevelopmentVersion=1.2.0-SNAPSHOT -Dtag=v1.1.2 -X do git checkout master or the desired branch