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

GIT_BRANCH not set when multiple branches are selected for build

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: git-plugin
    • Labels:
      None
    • Environment:
      Windows 7

      Description

      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.

      I have seen that getSingleBranch(build) returns null when that happens GIT_BRANCH is not exposed to the build.

        Activity

        Hide
        abayer abayer added a comment -

        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.

        Show
        abayer abayer added a comment - 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.
        Hide
        jadaks31 jadaks31 added a comment -

        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.

        Show
        jadaks31 jadaks31 added a comment - 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.
        Hide
        bergyman bergyman added a comment -

        Whether bug or feature request, this would be very awesome to have working when you have more than one branch set to be built by a project. Depending on which branch is currently being built, I need to be able to specify the maven repository it uses and the GIT_BRANCH environment variable would work perfect for this. As it is now, I have to have five different projects instead of one, one for each branch, to ensure they're using the proper maven repository. It's highly annoying.

        Show
        bergyman bergyman added a comment - Whether bug or feature request, this would be very awesome to have working when you have more than one branch set to be built by a project. Depending on which branch is currently being built, I need to be able to specify the maven repository it uses and the GIT_BRANCH environment variable would work perfect for this. As it is now, I have to have five different projects instead of one, one for each branch, to ensure they're using the proper maven repository. It's highly annoying.
        Hide
        squeedee Rasheed Abdul-Aziz added a comment -

        There is a workaround:

        try this in an "Execute Shell" build step:

           
        wget -O - ${BUILD_URL}api/json
        

        lastBuiltRevision in the api output looks like the info we need. I like the SHA as much as the branch. I would depend on the branch for 'which test server to use' and the SHA for 'precisely which source to use'

        Show
        squeedee Rasheed Abdul-Aziz added a comment - There is a workaround: try this in an "Execute Shell" build step: wget -O - ${BUILD_URL}api/json lastBuiltRevision in the api output looks like the info we need. I like the SHA as much as the branch. I would depend on the branch for 'which test server to use' and the SHA for 'precisely which source to use'
        Hide
        squeedee Rasheed Abdul-Aziz added a comment -

        Oh and i discovered that 1.1.5 of http://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin supports Parameterized build plugin, passing the SHA o the next build.

        Show
        squeedee Rasheed Abdul-Aziz added a comment - Oh and i discovered that 1.1.5 of http://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin supports Parameterized build plugin, passing the SHA o the next build.
        Hide
        cweiske_nr Christian Weiske added a comment -

        Today with Jenkins 1.430 and Git plugin 1.1.12, I can use $GIT_BRANCH in the job's workspace setting without problems - if I use one branch only or two.

        Show
        cweiske_nr Christian Weiske added a comment - Today with Jenkins 1.430 and Git plugin 1.1.12, I can use $GIT_BRANCH in the job's workspace setting without problems - if I use one branch only or two.
        Hide
        apaku Andreas Pakulat added a comment -

        I don't think thats true, its not fixed, the plugin just lost its ability to build multiple branches. At least it does not do that for me anymore. I've filed JENKINS-11337 for that now.

        Show
        apaku Andreas Pakulat added a comment - I don't think thats true, its not fixed, the plugin just lost its ability to build multiple branches. At least it does not do that for me anymore. I've filed JENKINS-11337 for that now.
        Hide
        cebe Carsten Brandt added a comment -

        Had it working with 1.454, updated to 1.457 and it now fails...
        Whats the problem with setting GIT_BRANCH env variable to the branch currently beeing built while build step (exec shell, etc...)

        Show
        cebe Carsten Brandt added a comment - Had it working with 1.454, updated to 1.457 and it now fails... Whats the problem with setting GIT_BRANCH env variable to the branch currently beeing built while build step (exec shell, etc...)

          People

          • Assignee:
            abayer abayer
            Reporter:
            jadaks31 jadaks31
          • Votes:
            5 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated: