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!

1 answer

0 vote

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 Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

697 views 0 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot