GIT_BRANCH = ${env.GI...">

Active Git branch - "(without branch)" on hudson CI

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 configured to be created when a branch changes. Console exit ...

 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 that he is creating a DPM-48 theme branch, but the GIT_BRANCH environment variable is not set, and the 'git branch' returns that git is in the “disconnected HEAD” state

 * (no branch) master DPM-48 

What I want to know is what branch I build the hudson on. There must be a way to do this.

+17
git git-checkout hudson
04 Oct 2018-10-10
source share
3 answers

RESOLVED

After watching the abayer comment in Hugson error 6856 , I took the following steps:

  • Using the Hudson Plugin Manager, I updated my Hudson Git Plugin version 1.1) to get a fix from the user.
  • Using the Hudson job configuration, I clicked the Advanced button in the Manage Sources section → Build Branches. Then I changed "Local branch to use" to what should be used for the name. No matter what.
  • Then I clicked on the Save button and started building using Build Now

alt text

The build log displays

 [workspace] $ git.exe checkout -b ChangeTester d6caef27759495c5714923c1ddf19551a70d6083 

Instead

 [workspace] $ git.exe checkout -f d6caef27759495c5714923c1ddf19551a70d6083 

This means that I am not in a “separate head” state and therefore I can commit, create tags and click.

I can use 'git rev-parse HEAD' to get the commit hash and find in the output 'git show-ref' to find the real branch name if I need it.

Now I can use successful build tags for my Git repository.

+32
Oct 29 '10 at 20:52
source share

Note: OP milkplus comment refers to the recent Hudson Error 6856 (June 2010), which states:

Git builds with the head disconnected no matter what

It is not yet clear whether this particular problem will be solved (the answers suggest that it can "work as designed"!), It also applies to this version of the hudson Git Plugin , which allows checking the local branch.




You are in DETACHED HEAD because, because the Git plugin is working right now, it made the checkout directly commit SHA1, not the HEAD branch.

The state you are in while your HEAD disconnected is not recorded by any branch (which is natural - you are not in any branch). This means that you can undo your temporary commits and merges by switching to an existing branch.

Your building script may first try to find which branch the corresponding commit comes from .




Since OP milkplus is implemented 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); } } 

The GIT_BRANCH environment variable is GIT_BRANCH , but it has no value in the xml script structure:

 <property environment="env"/> <echo>GIT_BRANCH = ${env.GIT_BRANCH}</echo> 

If so, this could be due to issue 7554 :

GIT_BRANCH not set when to build

multiple branches selected.

When I tried to determine in which branch the current assembly is enabled, I found that the GIT_BRANCH environment GIT_BRANCH not set when more than one branch was highlighted.

Actually this is not a mistake, as a function, I think - GIT_BRANCH env var is set only if there is one branch, so it does not matter if / when there are several branches. I'm not sure how we will format env var for multiple branches in this context.

I thought that GIT_BRANCH should be set by the branch that is currently being built. For example, if the assembly is on the main, it will contain a wizard.

This will help, for example, to click on another remote that was created during this assembly. Or Run another assembly with the correct set of branches to be created.

View of the NPE mirror described here

alt text

For some reason, the Git plugin started passing null for the GIT_BRANCH environment GIT_BRANCH .
This caused the Maven plugin to fail in a call to System.getProperties().putAll(systemProps) .

The solution was to use " master " as the default Git branch, rather than " ** " or an empty string.

+10
04 Oct '10 at 19:52
source share

Thank you for this decision!

I'm having trouble finding this optional dialog for setting up a local branch - and showing others that this is also still the current approach and in 2015 I would like to attach a screenshot of the current gui jenkins dialogs.

enter image description hereenter image description here

+2
Jan 20 '15 at 1:28
source share



All Articles