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

Cannot get branch name for Github Organizational Multibranch PR builds

    XMLWordPrintable

Details

    Description

      When using the GitHub Organizational Folder plugin, we have the option to Build origin PRs (unmerged head). I would love to use this feature, however in the Pipeline job that gets created and run for our PR's, I'm unable to find any way to get the branch name, which is absolutely necessary for various parts of our build process. 

      The ideal methods...

      env.BRANCH_NAME // returns PR-1234
      scm.branches[0] // returns PR-1234

      The often suggested hack, post-checkout...

      sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD') // returns HEAD
      

      ...returns "HEAD" and I'm not entirely sure why.

      Am I completely missing something here? This just seems like it would be painfully necessary for some people. Using `env.BRANCH_NAME` does work for the ordinary branch/non PR jobs. I found several older JIRA issues related to that, but cannot find anything related to the PR builds specifically. 

      Attachments

        Issue Links

          Activity

            hardwickj James Hardwick created issue -
            stephenconnolly Stephen Connolly made changes -
            Field Original Value New Value
            Link This issue depends on JENKINS-43507 [ JENKINS-43507 ]
            stephenconnolly Stephen Connolly made changes -
            Assignee Kohsuke Kawaguchi [ kohsuke ] Stephen Connolly [ stephenconnolly ]
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Resolved [ 5 ]
            stephenconnolly Stephen Connolly made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

            People

              stephenconnolly Stephen Connolly
              hardwickj James Hardwick
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: