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

Cannot get source branch in PR build in Bitbucket team project

      I need to get JIRA issue key from the name of the branch, but from the PR build I cannot obtain in. Source branch name is not listed in the 'env' list. It would be useful if we could somehow obtain the source branch name from the PR build

          [JENKINS-41104] Cannot get source branch in PR build in Bitbucket team project

          Ryan Campbell added a comment -

          This seems like a feature request to me, marking as such.

          Ryan Campbell added a comment - This seems like a feature request to me, marking as such.

          Gregory Kman added a comment - - edited

          I don't know that I would consider this a feature request. This seems more like a bug to me. I would imagine that the 'BRANCH_NAME=PR-4' should actually be what the source branch is in Git. 'BRANCH_NAME' is equivalent to 'SOURCE_NAME' and 'CHANGE_TARGET' to be equivalent to `TARGET_NAME`

          Am I mistaken? And if so could someone explain what 'BRANCH_NAME' and 'CHANGE_TARGET' are supposed to mean?

          Gregory Kman added a comment - - edited I don't know that I would consider this a feature request. This seems more like a bug to me. I would imagine that the 'BRANCH_NAME=PR-4' should actually be what the source branch is in Git. 'BRANCH_NAME' is equivalent to 'SOURCE_NAME' and 'CHANGE_TARGET' to be equivalent to `TARGET_NAME` Am I mistaken? And if so could someone explain what 'BRANCH_NAME' and 'CHANGE_TARGET' are supposed to mean?

          Jesse Glick added a comment -

          BRANCH_NAME is the head name as far as Jenkins core infrastructure is concerned; modulo escaping, it will be the same as JOB_BASE_NAME.

          CHANGE_TARGET is the expected merge target, such as master typically.

          Jesse Glick added a comment - BRANCH_NAME is the head name as far as Jenkins core infrastructure is concerned; modulo escaping, it will be the same as JOB_BASE_NAME . CHANGE_TARGET is the expected merge target, such as master typically.

          Stephen Connolly added a comment - https://github.com/jenkinsci/branch-api-plugin/blob/e4399aa99bc8dac1fae47915f995c2f93e7e955e/src/main/java/jenkins/branch/BranchNameContributor.java#L69  should be the fix.

          I claim resolved in branch-api 2.0.11

          Stephen Connolly added a comment - I claim resolved in branch-api 2.0.11

          Marcin L added a comment - - edited

          I updated to the latest 2.0.11 but still I can't get the source branch name. It's always set to "PR-" but I think it should be set to `head.ref` from Github api?

          Marcin L added a comment - - edited I updated to the latest 2.0.11 but still I can't get the source branch name. It's always set to "PR-" but I think it should be set to `head.ref` from Github api?

          Jesse Glick added a comment -

          marcinl $CHANGE_BRANCH

          Jesse Glick added a comment - marcinl $CHANGE_BRANCH

          Marcin L added a comment -

          I checked and $CHANGE_BRANCH environment variable is not set. This is my current setup:

          Are you sure it's working with GitHub PRs? I saw some comments online that it's only working with BitBucket.

          Marcin L added a comment - I checked and $CHANGE_BRANCH environment variable is not set. This is my current setup: Are you sure it's working with GitHub PRs? I saw some comments online that it's only working with BitBucket.

          Joe Pea added a comment -

          Hello, how can we use the original branch for pull request builds, instead of the PR-XXX branches?

          Joe Pea added a comment - Hello, how can we use the original branch for pull request builds, instead of the PR-XXX branches?

          Joe Pea added a comment -

          Figured it out. I set the `Discover branches Strategy` to `only branches that are filed as PRs`, and removed the `discover pull requests` options. Now it builds straight from my pull request branches, exactly like I wanted.

          Joe Pea added a comment - Figured it out. I set the `Discover branches Strategy` to `only branches that are filed as PRs`, and removed the `discover pull requests` options. Now it builds straight from my pull request branches, exactly like I wanted.

            Unassigned Unassigned
            pkozikow Paweł Kozikowski
            Votes:
            4 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: