Jenkins: Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref

I’ve moved some of my projects from SVN to GIT. In Jenkins, builds are working fine but when I try to release, I get the following stack trace

 Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) on project hello_world_app: 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]
[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.
[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

I think this is a common issue sometimes occur when we try to release a project in Jenkins though the project itself may be successfully built when we run the build using link “Build Now”.

For example, you have the project in GIT repository and there you have branches like “develop” and “master”. When you want to release the project for deploying on Dev, SIT and UAT, you would like to build and release from “develop’ branch, and when you want the project for production release then you would like to build and release from “master” branch. Therefore, you want to click on “Perform maven release” in Jenkins to release an artifact for the project either from “develop” or “master” branch and you may face the error similar to the following

“Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref”

Continue reading “Jenkins: Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref”