Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Pipelines - Unable to push to same docker tag as the commit tag

IT
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 8, 2023


I want to push my built images to docker hub with the same tags like the commit tag but get this error message:

Error parsing reference: "bruyland/nest-appinfo-test:" is not a valid repository/tag: invalid reference format

It's obvious that the `$BITBUCKET_TAG` variable is empty, but I dpon't understand why.

Here's the pipeline, I've been following this recipe: https://think-engineer.com/blog/devops/bitbucket-pipelines-building-publishing-and-re-tagging-docker-images-in-a-ci-cd-workflow

options:
  docker: true
  steps:
    - step: &build-and-push
        size: 2x
        name: build and push docker image
        script:
          # build the Docker image
          # origional IMAGE_NAME export IMAGE_NAME=myorg/myapp:$BITBUCKET_BRANCH-$BITBUCKET_COMMIT
          - export IMAGE_NAME=bruyland/$BITBUCKET_REPO_SLUG
          - echo '"$IMAGE_NAME"'
          - docker build --build-arg COMMIT=$BITBUCKET_COMMIT --build-arg TAG=$BITBUCKET_TAG -t $IMAGE_NAME .
          # authenticate with the Docker Hub registry
          - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
          # push the new Docker image to the Docker registry
          - docker push $IMAGE_NAME
pipelines:
  branches:
    develop:
      - step: *build-and-push
    master:
      - step: *build-and-push
  tags:
    '*':
      # - step: *build-and-push
      - step:
          name: retag and repush image
          script:
            # get the image that was built in the master branch
            - export IMAGE_NAME=bruyland/$BITBUCKET_REPO_SLUG
            - echo '"$BITBUCKET_TAG"'
            - export NEW_IMAGE_NAME=$IMAGE_NAME:$BITBUCKET_TAG
            # authenticate with the Docker Hub registry
            - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
            # pull the image down
            - docker pull $IMAGE_NAME
            # retag the image using the git tag
            - docker tag $IMAGE_NAME $NEW_IMAGE_NAME
            # push the image back
            - docker push $NEW_IMAGE_NAME

 

1 answer

1 accepted

2 votes
Answer accepted
IT
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 8, 2023

Found the problem, forgot to add `--tags` to the git push command.

Sorry for asking such a stupid question

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events