Active Git branch is "(no branch)" on hudson CI
git, git-checkout, hudson
Solution
RESOLVED
After seeing the comment by abayer in Hudson bug 6856, I took the following steps:
- Using the Hudson Plugin Manager, I updated my Hudson Git Plugin version 1.1) to get abayer's fix.
- Using the Hudson Job Configuration, I clicked the "Advanced" button under "Source Code Management" -> "Branches to Build". I then changed the "Local branch to use" to something to use for a name. It doesn't matter what.
- Then I clicked the "Save" button and started a build with "Build Now"
The build log shows
[workspace] $ git.exe checkout -b ChangeTester d6caef27759495c5714923c1ddf19551a70d6083
Instead of
[workspace] $ git.exe checkout -f d6caef27759495c5714923c1ddf19551a70d6083
Which means that I am not in a 'detached head' state and can therefore do commits, create tags, and push.
I can use 'git rev-parse HEAD' to get the commit hash and find that in the output of 'git show-ref' to find the real name of the branch if I need it.
I'm now able to push successful build tags to my git repo.
Problem
My Ant build.xml script starts with ``` <property environment="env"/> <echo>GIT_BRANCH = ${env.GIT_BRANCH}</echo> <echo>PWD = ${env.PWD}</echo> ``` Hudson CI is setup to build when any branch changes. Console output is... ``` Commencing build of Revision 90906a63929e9074035eb5b10c71ee055ad3e13c (origin/DPM-48) GitAPI created Checking out Revision 90906a63929e9074035eb5b10c71ee055ad3e13c (origin/DPM-48) [workspace] $ git.exe checkout -f 90906a63929e9074035eb5b10c71ee055ad3e13c [workspace] $ cmd.exe /C '"C:\Program Files\WinAnt\bin\ant.bat" -file build.xml ...' [echo] GIT_BRANCH = ${env.GIT_BRANCH} [echo] PWD = /cygdrive/d/.hudson ``` From the console output, Hudson knows it is building topic branch DPM-48 but environment variable GIT_BRANCH is not set and 'git branch' returns that git is at a 'detached HEAD' state ``` * (no branch) master DPM-48 ``` What I want to know is which branch I'm building on hudson. There must be a way to do this.