Fix issue in bash syntax around the pushing of Docker images in the registry
What was added in !98 (merged) didn't fully work in fact: the jobs were considered as passed, but in fact it choked on a shell command:
#9 DONE 6.5s
#4 [1/5] FROM docker.io/library/fedora:latest@sha256:61864fd19bbd64d620f338eb11dae9e8759bf7fa97302ac6c43865c48dccd679
$ if [ $CI_COMMIT_TAG -ne '' ]; then # collapsed multi-line command
sh: : unknown operand
Cleaning up project directory and file based variables 00:00
Job succeeded
Yaml was:
.build_docker_image: &build_docker_image
stage: build
image: docker
retry: 2
tags:
- ci.inria.fr
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build -f docker/Dockerfile.${NAME} -t ${NAME} .
# Push the image to the GitLab registry only if the pipeline was triggered by a tag
- |
if [ $CI_COMMIT_TAG -ne '' ]; then
docker tag ${NAME} $CI_REGISTRY/$CI_PROJECT_PATH/${NAME}:latest
docker push $CI_REGISTRY/$CI_PROJECT_PATH/${NAME}:latest
docker tag ${NAME} $CI_REGISTRY/$CI_PROJECT_PATH/${NAME}:${CI_COMMIT_TAG}
docker push $CI_REGISTRY/$CI_PROJECT_PATH/${NAME}:${CI_COMMIT_TAG}
fi
rules:
# Launch docker build if the Dockerfile has changed or if the pipeline was triggered by a tag
- if: '$CI_COMMIT_TAG'
- changes:
- docker/Dockerfile.${NAME}
Following @vrouvrea, we added another condition:
if [ ! -z ${CI_COMMIT_TAG} ]; then
if [ $CI_COMMIT_TAG -ne '' ]; then
docker tag ${NAME} $CI_REGISTRY/$CI_PROJECT_PATH/${NAME}:latest
docker push $CI_REGISTRY/$CI_PROJECT_PATH/${NAME}:latest
docker tag ${NAME} $CI_REGISTRY/$CI_PROJECT_PATH/${NAME}:${CI_COMMIT_TAG}
docker push $CI_REGISTRY/$CI_PROJECT_PATH/${NAME}:${CI_COMMIT_TAG}
fi
fi
to fix it.