When using the Maven Release Plugin with git and jenkins I got the error
[INFO] Executing: /bin/sh -c cd /home/tom1299/jenkins/workspace/cloud-examples-release && git symbolic-ref HEAD
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5:prepare (default-cli) on project cloud-examples: 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]
during the prepare goal. Fortunately their is an easy solution:
The solution for this problem is described in this post on StackOverflow. The cause of the problem seems to be that the git plugin checks out the branch in detached head state. HEAD is a pointer which tells you which branch you are on. This pointer apparently gets lost while doing the checkout with the Jenkins GIT Plugin.
The problem can be solved in Jenkins by specifying a local branch name for the parameter “Checkout/merge to local branch (optional)” under “Source Code Management”:
A nice explanation of detached head can be found here.
You should also not use shallow clones to avoid this problem.
This problem can be solved by checking out to a named local branch and not using shallow cloning in your jenkins job.