BITBUCKET_BRANCH Pipelines Environment Variable is Empty

darklordofthesmith November 6, 2017

Hello,

I'm attempting to use bitbucket pipelines to create docker images and tag them with the branch name. The problem I'm having is that the $BITBUCKET_BRANCH is always empty, which I've checked by echoing the variable as the first step in the build. I've tried this both for branch builds and for custom builds that I run from the branch and in both cases the variable is empty. Here is my yaml file:

options:
docker: true
pipelines:
custom:
build_branch_image:
-
step:
script:
- echo $BITBUCKET_BRANCH
- aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION | sh
- docker build --tag=ecd_service:$BITBUCKET_BRANCH .
- docker tag ecd_service:$BITBUCKET_BRANCH $AWS_ECR_URI/ecd_service:$BITBUCKET_BRANCH
- docker push $AWS_ECR_URI/ecd_service:$BITBUCKET_BRANCH
branches:
8_09_CAM_2246:
-
step:
script:
- echo $BITBUCKET_BRANCH
- docker build --tag=ecd_service:$BITBUCKET_BRANCH .
- docker tag ecd_service:$BITBUCKET_BRANCH $AWS_ECR_URI/ecd_service:$BITBUCKET_BRANCH
- docker push $AWS_ECR_URI/ecd_service:$BITBUCKET_BRANCH

 Thank you!

3 answers

1 vote
ceci82 March 9, 2018

I have the same problem

Ruslanas January 6, 2019

A work round could be to get a branch name by yourself in the script if variable is empty. I use for mercurial:

if [ -z "$BITBUCKET_BRANCH" ]; then BITBUCKET_BRANCH=$(hg branch); fi;

 

0 votes
Marcel Lange April 4, 2018

just called export before I needed one of this vars and then they where accessible.

0 votes
jbane December 12, 2017

It seems to me like it should work for "branches" (but not "custom") builds according to this:

BITBUCKET_BRANCH

The branch on which the build was kicked off. This value is only available on branches. Not available for builds against tags, or custom pipelines.

However, as you stated, it doesn't appear to be set even in that case. Seems like maybe a bug or incorrect docs?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events