BITBUCKET_BRANCH Pipelines Environment Variable is Empty Edited

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

This widget could not be displayed.

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?

This widget could not be displayed.

I have the same problem

This widget could not be displayed.

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,185 views 8 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you