My bitbucket pipelines are failing with tag does not exist referring to dockerhub image push
this is the bitbucket-pipelines.yaml config
image: node:8
pipelines:
default:
- step:
name: Build Docker Image
caches:
- docker
script:
- echo 'Building Docker image but skipping Deploy for feature branch'
- sh ./build-docker.sh
branches:
development:
- step:
name: Deploy to Development
caches:
- docker
deployment: test
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh development ${LABEL}
staging:
- step:
name: Deploy to Staging
caches:
- docker
deployment: staging
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh staging ${LABEL}
qa:
- step:
name: Deploy to QA
caches:
- docker
deployment: production
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh qa ${LABEL}
demo:
- step:
name: Deploy to Demo
caches:
- docker
deployment: test
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh demo ${LABEL}
master:
- step:
name: Deploy to Production
caches:
- docker
deployment: production
script:
- export DOCKER_BUILDKIT=0
- export LABEL=$(TZ=':America/Phoenix' date +%Y%m%d%H%M)
- sh ./deploy.sh master ${LABEL}
options:
docker: true
build-docker.sh
and deploy.sh
#!/usr/bin/env bash
ENV=${1}
COMMIT=${BITBUCKET_COMMIT}-${2}
# Build Docker image and push to repository
docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
docker build -t intraedge/truyo-php:${ENV}-${COMMIT} -t intraedge/truyo-php:${ENV} --build-arg env=${ENV} .
docker push intraedge/truyo-php:${ENV}
docker push intraedge/truyo-php:${ENV}-${COMMIT}
the docker version being used is
+ docker version
Client:
Version: 20.10.24
API version: 1.39
Go version: go1.19.7
Git commit: 297e128
Built: Tue Apr 4 18:17:06 2023
OS/Arch: linux/amd64
Context: default
Experimental: true
check the below article which mentions same issue as mine
https://confluence.atlassian.com/bbkb/docker-push-failing-tag-does-not-exist-1142430671.html
In June 2022, Bitbucket Pipelines upgraded to Docker CLI version v20.10.15. Prior to Docker CLI version 20, the docker push
command would push all available image tags if no tag was specified. For version 20, the Docker CLI updated the docker push
command to try to push the latest
tag, if a tag is not specified. If the latest
tag does not exist, the command will fail.
It mentions
But this did not help us
pipelines:
default:
- step:
services:
- docker
script:
- curl -s -O https://download.docker.com/linux/static/stable/x86_64/docker-19.03.15.tgz
- tar --extract --file=docker-19.03.15.tgz
- ls -al ./docker
- export PATH=./docker:$PATH
- which docker
- docker version
any other solution would be appreciated
Hi @Nisanth Reddy,
The first line of the build-docker.sh is
ENVIRONMENT=${1}
${1} refers to the first command-line argument passed to the shell script, but in your yml file you are not passing any arguments to the script:
- sh ./build-docker.sh
So, the ENVIRONMENT variable (which is used for the tags of the Docker image you build) is empty.
Can you try adjusting the command and passing an argument to the script?
The knowledge base article you posted is not relevant because it concerns cases where no tag is specified in the docker push command. Your docker push commands include tags with the image.
Can you also please confirm if you have in your yml file
services:
- docker
for the step
or
options:
docker: true
at the top level. You would see a different error without one of these options, but I just wanted to bring it up because you are running docker commands and the yml you posted here doesn't include an option for the docker service.
Kind regards,
Theodora
Hi @Theodora Boudale thanks for responding, I can confirm that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Theodora Boudale I added the entire code of pipeline.yaml and the docker version.
Thanks & Regards,
Nisanth Reddy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nisanth Reddy,
Thank you for sharing additional info.
Your yml file has several pipelines. There is the default pipeline, and the branches pipelines development, staging, qa, demo, master.
When you run the sh ./deploy.sh command in the branches pipelines, you specify arguments. For example, the command in the development pipeline is
- sh ./deploy.sh development ${LABEL}
In this case, ${1} refers to development and the variable ENVIRONMENT has the value development.
However, the default pipeline has the command
- sh ./build-docker.sh
so there are no arguments to the script and ${1} is empty (and ENVIRONMENT is also empty).
Is it the default pipeline that shows this error or one of the branches pipeline?
Kind regards,
Theodora
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.