Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Feature Request: Add BITBUCKET_STEP_NAME variable

Deleted user April 8, 2020

I am trying to build multiple Docker images with less code duplication.

 

Every step is doing:

- docker build -t ${ECR_ENDPOINT}/${IMAGE_NAME}:${BITBUCKET_BRANCH} .
- docker push ${ECR_ENDPOINT}/${IMAGE_NAME}:${BITBUCKET_BRANCH}

 

But it is not possible to set IMAGE_NAME variable per step.

Maybe if BITBUCKET_STEP_NAME is available, I can put the docker image name there ?

 

https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html

 

Right now I am hacking with:

 

- if [[ $BITBUCKET_PARALLEL_STEP -eq 0 ]];then IMAGE_NAME="image";fi
- if [[ $BITBUCKET_PARALLEL_STEP -eq 1 ]];then IMAGE_NAME="another-image";fi
- if [[ $BITBUCKET_PARALLEL_STEP -eq 2 ]];then IMAGE_NAME="image-foo";fi
- aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${ECR_ENDPOINT}/${IMAGE_NAME}
- cd ${IMAGE_NAME}
- docker build -t ${ECR_ENDPOINT}/${IMAGE_NAME}:${BITBUCKET_BRANCH} .
- docker push ${ECR_ENDPOINT}/${IMAGE_NAME}:${BITBUCKET_BRANCH}

1 answer

0 votes
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 8, 2020

Hello @[deleted] ,

Welcome to the Community!

I tagged your question so that Pipelines team will see it sooner.

I'm not saying this is invalid – it totally makes sense to me, – but in this particular case it might be easier (in terms of maintenance) to switch to build scripts stored somewhere in your repository which then are called by Pipelines steps. You'll get all the power of whatever script language you'll be using, while Pipelines will orchestrate the process by pulling the right threads.

So each of the parallel steps would call the very same script with a single parameter – image name.

Does this make sense?

Cheers,
Daniil 

Deleted user April 10, 2020

Hello Daniil ,

Thanks for this solution, I might use it for more complex scenarios.

The problem here is that I won't be able to do this even with a script:

 

 - step:
name: my-image
script: *build-push
services:
- docker
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 10, 2020

Hm, I didn't get this, sorry.

What I meant was you can create a script like this:

#!/bin/bash

IMAGE_NAME=$1

aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${ECR_ENDPOINT}/${IMAGE_NAME}

cd ${IMAGE_NAME}
docker build -t ${ECR_ENDPOINT}/${IMAGE_NAME}:${BITBUCKET_BRANCH} .
docker push ${ECR_ENDPOINT}/${IMAGE_NAME}:${BITBUCKET_BRANCH}

and save it in your repository, let's say as bin/docker-build-push.sh (don't forget to commit it with executable bit on, otherwise you'd need to chmod +x in the pipeline).

Now, the the parallel steps in your pipeline would look like this:

- parallel:
- step:
services:
- docker
script:
- bin/docker-build-push.sh "image"
- step:
 services:
- docker
script:
- bin/docker-build-push.sh "another-image"
- step:
services:
- docker
script:
- bin/docker-build-push.sh "image-foo"

This is an equivalent of what you posted in the original message, if I got it right, and it solves duplication problem.

Hope this helps.

Cheers,
Daniil

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events