Getting the branch a pull request is created from?

I’ve been trying to get an environment variable telling me what branch a pull request is created from, but the environment variables like $DRONE_BRANCH or $DRONE_COMMIT_BRANCH from the documentation only give as value the branch the pull request is going to be merged into.

I’m just wondering, is there any way to get that branch name at all now? And if not, could it be added?

I also know someone that uses the same environment variable but has repositories on Bitbucket (mines are on Github), and the behaviour seems to be correct on Bitbucket. Is there a difference between the two integrations?

1 Like

This information is contained in the DRONE_REFSPEC environment variable, which includes the source and target branch, colon separated.

Sorry for piggybacking on this issue, but I fail to add the var you suggest ( or any other built in var for that matter) as a tag to my image.

    image: plugins/docker
    repo: my_registry/my_repo/service
    registry: my_registry
      - docker_username
      - docker_password
      - ${DRONE_REFSPEC}

resulting in

Successfully tagged 00000000:latest
/usr/local/bin/docker tag 00000000 my_registry/my_repo/service:
Error parsing reference: “my_registry/my_repo/service:” is not a valid repository/tag: invalid reference format
time=“2017-09-20T14:42:19Z” level=fatal msg="exit status 1"
2017/09/20 16:42:19 drone_step_0 : exit code 1

The refspec value is only populated for GitHub pull requests at this time.

Example pull request with refspec:

Example push with respec empty:

for future users with the same question:


for an up-to-date list see:

1 Like