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!
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
just called export before I needed one of this vars and then they where accessible.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.