Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-33984

Git plugin sets wrong branch name GIT_BRANCH (more than 2 branches with same SHA1)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: git-plugin
    • Labels:
      None
    • Environment:
      Production
    • Similar Issues:

      Description

      Git plugin ver: 2.4.4

      In jenkins job we configure Git plugin ->
      Branches to build/Branch specifier: origin/ready/**

      Developer pushes code to central git repository, which Jenkins check into 2 branches:
      git push origin bugfix:sergey/bugfix
      git push origin bugfix:ready/bugfix

      When Jenkins job kicks in, it provides this output:

      14:01:36 > git branch -a -v --no-abbrev --contains 24ef859065480d5ac965652cfce8a0dd959fd082 # timeout=10
      14:01:36 Checking out Revision 24ef859065480d5ac965652cfce8a0dd959fd082 (origin/sergey/bugfix, origin/ready/bugfix)
      ..
      ..

      14:01:36 HOME=/var/lib/jenkins
      14:01:36 GIT_BRANCH=origin/sergey/bugfix
      14:01:36 EXECUTOR_NUMBER=1

      As you can see GIT_BRANCH got set to "origin/sergey/bugfix"
      and this is wrong because we asked for branch to match origin/ready/**

      This causes problems in our build process

        Attachments

          Issue Links

            Activity

            Hide
            stealthii Dan Porter added a comment -

            This is still a problematic issue. It seems that $GIT_BRANCH is set to whatever the first identified branch is for that commit, rather than the triggering branch received by Jenkins.

            Example of feature/awful, as the only branch pointing at this id, working:

            Checking out Revision d0903cd1d7fab333f84fa8094af14552cc17355c (origin/feature/awful)
            GIT_BRANCH is 'origin/feature/awful'

            Example of master, of which develop is also pointing at this commit id, not working:

            Checking out Revision 62e085f7ab8163c305bef91e07314a5f09d2ed5a (origin/develop, origin/master)
            GIT_BRANCH is 'origin/develop'
            Show
            stealthii Dan Porter added a comment - This is still a problematic issue. It seems that $GIT_BRANCH is set to whatever the first identified branch is for that commit, rather than the triggering branch received by Jenkins. Example of feature/awful , as the only branch pointing at this id, working: Checking out Revision d0903cd1d7fab333f84fa8094af14552cc17355c (origin/feature/awful) GIT_BRANCH is 'origin/feature/awful' Example of master , of which develop is also pointing at this commit id, not working: Checking out Revision 62e085f7ab8163c305bef91e07314a5f09d2ed5a (origin/develop, origin/master) GIT_BRANCH is 'origin/develop'
            Hide
            jstarbird Jon Starbird added a comment -

            For us, the job will build the correct branch and if you look at the Environment Variables after the build the GIT_BRANCH variable is set to the correct value but if you use the GIT_BRANCH variable for Email for example the value is wrong.  Recorded Revision numbers are correct as well.

            Does anyone know of another, more reliable way, to get the Branch built? Hard to believe with how long Git has been around in Jenkins that this is still an issue.

            Show
            jstarbird Jon Starbird added a comment - For us, the job will build the correct branch and if you look at the Environment Variables after the build the GIT_BRANCH variable is set to the correct value but if you use the GIT_BRANCH variable for Email for example the value is wrong.  Recorded Revision numbers are correct as well. Does anyone know of another, more reliable way, to get the Branch built? Hard to believe with how long Git has been around in Jenkins that this is still an issue.
            Hide
            markewaite Mark Waite added a comment -

            Jon Starbird you could use a multi-branch pipeline with a Jenkinsfile in the root directory of each branch, then let it create a job for each branch.  When a change arrives on a branch, it is built, with the settings for that branch.  That has the added benefit of placing the job definition into source code instead of capturing the job definition as Jenkins job definition.

            Show
            markewaite Mark Waite added a comment - Jon Starbird you could use a multi-branch pipeline with a Jenkinsfile in the root directory of each branch, then let it create a job for each branch.  When a change arrives on a branch, it is built, with the settings for that branch.  That has the added benefit of placing the job definition into source code instead of capturing the job definition as Jenkins job definition.
            Hide
            jstarbird Jon Starbird added a comment -

            Mark Waite I'm new to Git so I'm not to sure how to work that out for the GitFlow setup we're using and building feature branches. But I'll look into that. Thanks.

            Show
            jstarbird Jon Starbird added a comment - Mark Waite  I'm new to Git so I'm not to sure how to work that out for the GitFlow setup we're using and building feature branches. But I'll look into that. Thanks.
            Hide
            chongj615 Jeff Chong added a comment -

            using git version 4.0.0, this problem is still there.

            I guess you cannot trust GIT_BRANCH variable.

            Show
            chongj615 Jeff Chong added a comment - using git version 4.0.0, this problem is still there. I guess you cannot trust GIT_BRANCH variable.

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              sleonovich Sergey Leonovich
              Votes:
              14 Vote for this issue
              Watchers:
              20 Start watching this issue

                Dates

                Created:
                Updated: