Note: the OP milkplus's comment refers to recent Hudson bug 6856 (June 2010), which mentions:
Git builds with detached head no matter what
While it is unclear if that particular issue will be solved (answers suggest it might actually "work as designed"!), it also refers to this version of hudson Git Plugin, allowing to checkout a local branch.
You are in a DETACHED HEAD
because, as the git plugin is working right now, it did checkout directly a commit SHA1, and not a branch HEAD
.
The state you are in while your HEAD
is detached is not recorded by any branch (which is natural --- you are not on any branch).
What this means is that you can discard your temporary commits and merges by switching back to an existing branch.
Your building script could first try to find what branch the relevant commit is coming from.
As the OP milkplus realized by looking at the source code of the Hudson Git Plugin:
public void buildEnvVars(AbstractBuild build, java.util.Map<String, String> env) {
super.buildEnvVars(build, env);
String branch = getSingleBranch(build);
if(branch != null){
env.put(GIT_BRANCH, branch);
}
}
An environment variable GIT_BRANCH
is set, but it doesn't appear to have any value in the xml build script:
<property environment="env"/>
<echo>GIT_BRANCH = ${env.GIT_BRANCH}</echo>
If that is the case, it may be because of issue 7554:
GIT_BRANCH
not set when multiple branches are selected for build
When trying to identify what branch the current build are on, I found that the GIT_BRANCH
environment variable is not set when more then a single branch is selected to be built.
This isn't really a bug so much as a feature request, I think - the GIT_BRANCH
env var is only set if there's a single branch, so as such, it's not relevant if/when there are multiple branches. I'm not sure how we'd format an env var for multiple branches in this context.
I thought that GIT_BRANCH
shall be set to the branch that is currently building.
Like if the build is on master it will contain the master.
That would help to for example push to another remote that branch that was built during this build.
Or Triggering another Build with the correct branch set to be built.
Kind of mirror the NPE described here
For some reason Git plugin started to pass null value for GIT_BRANCH
environment variable.
This caused Maven plugin to fail in System.getProperties().putAll(systemProps)
call.
The solution was to use "master
" as default Git branch instead of "**
" or empty String.