How to push multiple tags with ECR push pipelines

Yadvendra_Singh September 24, 2019

I am trying to push multiple Tags with

pipe: atlassian/aws-ecr-push-image:0.1.2

 

i need something like 

TAG: '${BITBUCKET_BUILD_NUMBER}:latest'

 

2 answers

1 vote
Alexander Zhukov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 25, 2019

Update: This solution doesn't work, please use @james.twigg's solution instead.

You can apply multiple tags to your image before using the pipe. All tags will be pushed by the pipes at once

script:
  - docker build -t <image-name> -t <docker-repository>/<image-name>:${BITBUCKET_BUILD_NUMBER} .
- docker tag <docker-repository>/<image-name>:${BITBUCKET_BUILD_NUMBER} <docker-repository>/<image-name>:latest
- pipe: atlassian/aws-ecr-push-image:0.1.2 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION IMAGE_NAME: <image-name>

You can also have a look at the similar question in StackOverflow: https://stackoverflow.com/a/31963727/2183102

Yadvendra_Singh September 25, 2019

Thanks Alexander

I tried this

- docker build -t <IMAGE_NAME> -t ${AWS_REGISTRY_URL}:${BITBUCKET_BUILD_NUMBER} .
- docker tag ${AWS_REGISTRY_URL}:${BITBUCKET_BUILD_NUMBER} ${AWS_REGISTRY_URL}:latest
- pipe: atlassian/aws-ecr-push-image:0.1.2
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: <IMAGE_NAME>

 

AWS_REGISTRY_URL is like <AWS_ACCOUNT_NUMBER>.dkr.ecr.eu-west-1.amazonaws.com/<IMAGE_NAME>

 

still getting only default TAG 'latest'

Like james.twigg likes this
james.twigg October 8, 2019

Hi Yadvendra,

I encountered the same problem with `aws-ecr-push-image:0.1.3`, only the 'latest' tag would be set.

As a workaround I included two instances of the pipe in the step:

- docker build -t <IMAGE_NAME>:latest -t <IMAGE_NAME>:${BITBUCKET_BUILD_NUMBER} .
- pipe: atlassian/aws-ecr-push-image:0.1.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: <IMAGE_NAME>
TAG: latest
- pipe: atlassian/aws-ecr-push-image:0.1.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: <IMAGE_NAME>
TAG: ${BITBUCKET_BUILD_NUMBER}

The image was not actually uploaded again but the extra tag was added to the image uploaded as 'latest'.

Like # people like this
Yadvendra_Singh October 9, 2019

Thanks James,

I tried your solution but got the error

--env=TAG="${BITBUCKET_BUILD_NUMBER}" \ --add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \ bitbucketpipelines/aws-ecr-push-image:0.1.3✖ Validation errors: TAG:- must be of string type

 

my pipeline is like this

- docker build -t bgs:latest -t bgs:${BITBUCKET_BUILD_NUMBER} .

- pipe: atlassian/aws-ecr-push-image:0.1.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: bgs
TAG: latest

- pipe: atlassian/aws-ecr-push-image:0.1.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: bgs
TAG: ${BITBUCKET_BUILD_NUMBER}

 

Bix December 4, 2019

I believe you may be able to use the `TAGS` field with a space delimited set of tags:

```
TAGS: "tag1 tag2"
```

0 votes
Vinay Muralimohan September 29, 2020

I have the same error ✖ Validation errors: TAGS:- must be of string type.

Have this pipeline step. Help is much appreciated.

image: atlassian/default-image:2

pipelines:
default:
- step:
name: "Build and Push"
script:
# build the image
- docker build -t dockerdemo:${BITBUCKET_BUILD_NUMBER} .

# use the pipe to push the image to AWS ECR
- pipe: atlassian/aws-ecr-push-image:1.2.0
variables:
IMAGE_NAME: dockerdemo
TAG: ${BITBUCKET_BUILD_NUMBER}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events