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

0 vote
Joe Bane I'm New Here Dec 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?

I have the same problem

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Asked 12m ago in Confluence

What are the resources that you use to learn more about Atlassian Products?

I am gathering information about resources available for Atlassian product knowledge transferring for a presentation in our local Atlassian User Group. I want to group them in four categories From ...

3 views 0 1
View question

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