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

          Paweł Kozikowski created issue -

          Mike Kobit added a comment -

          It looks like the env.BRANCH_NAME is not the origin branch in pull requests, it is the PR number.

          Mike Kobit added a comment - It looks like the env.BRANCH_NAME is not the origin branch in pull requests, it is the PR number.

          Michael Neale added a comment -

          Hi mkobit what version of the branch-api-plugin do you have installed?

          Michael Neale added a comment - Hi mkobit what version of the branch-api-plugin do you have installed?

          Mike Kobit added a comment -

          michaelneale this happened with the older (as of whatever the latest version was) yesterday. I tested this today with a simple sh 'env' step after updating all of our plugins to the 2.0 line (based on this blog post) and now we see something like:

          # ... some other env variables
          CHANGE_URL=https://git.corp.com/projects/proj/repos/repository/pull-requests/4/overview
          CHANGE_ID=4
          BRANCH_NAME=PR-4
          CHANGE_TITLE=This is the commit message in the PR
          CHANGE_TARGET=master
          

          I don't believe that CHANGE_TARGET was available before the plugin updates but I could be wrong. I don't see anything regarding the source branch in the PR available as an environment variable (may be separate from this issue).

          Note that this is with Bitbucket Server 4.11 (not Bitbucket Cloud).

          Mike Kobit added a comment - michaelneale this happened with the older (as of whatever the latest version was) yesterday. I tested this today with a simple sh 'env' step after updating all of our plugins to the 2.0 line (based on this blog post ) and now we see something like: # ... some other env variables CHANGE_URL=https://git.corp.com/projects/proj/repos/repository/pull-requests/4/overview CHANGE_ID=4 BRANCH_NAME=PR-4 CHANGE_TITLE=This is the commit message in the PR CHANGE_TARGET=master I don't believe that CHANGE_TARGET was available before the plugin updates but I could be wrong. I don't see anything regarding the source branch in the PR available as an environment variable (may be separate from this issue). Note that this is with Bitbucket Server 4.11 (not Bitbucket Cloud).

          Mike Kobit added a comment -

          michaelneale is this more of a Branch API issue or is it specific to the Bitbucket Branch Source plugin?

          Mike Kobit added a comment - michaelneale is this more of a Branch API issue or is it specific to the Bitbucket Branch Source plugin?

          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.
          Ryan Campbell made changes -
          Issue Type Original: Bug [ 1 ] New: New Feature [ 2 ]

          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?
          Mike Kobit made changes -
          Component/s New: branch-api-plugin [ 18621 ]

          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.

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

              Created:
              Updated:
              Resolved: