In the cleanup stage of my gitlab-ci pipeline im deleting the temporary docker tags that were generated before testing. The images are retagged in the publish stage. When deleting the original tag, the retag is also deleted. The stages are:
build:
script:
- docker build [...] $CI_REGISTRY_IMAGE/<image-name>:${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG} [...]
- docker push $CI_REGISTRY_IMAGE/<image-name>:${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG} [...]
test:
# do some testing
publish:
script:
- docker pull $CI_REGISTRY_IMAGE/<image-name>:${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG}
- docker tag $CI_REGISTRY_IMAGE/<image-name>:${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG} $CI_REGISTRY_IMAGE/<image-name>:${CI_COMMIT_REF_SLUG}
- docker push $CI_REGISTRY_IMAGE/<image-name>:${CI_COMMIT_REF_SLUG}
cleanup:
when: always
script:
- 'curl --request DELETE --header "PRIVATE-TOKEN: ${GITLAB_PAT}" "<gitlab-url>/api/v4/projects/<project-path>/registry/repositories/<repository-id>/tags/${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG}"'
After this runs, the tag ${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG}
and ${CI_COMMIT_REF_SLUG}
are both deleted when from my understanding only ${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG}
should be deleted. The tags are created as expected and remain if the cleanup stage is cancelled. The same behavior occurs when deleting the tags through the ui. If i left out anything relevant to this problem while sanitizing the stages please let me know.
Okay i figured out what the problem was. It seems that i've run into this issue. One possible workaround is to tag some arbitrary image the same as the one you want to delete and push that over the old one. After that you can delete the tag without deleting the retag:
docker pull alpine:latest
docker tag alpine:latest $CI_REGISTRY_IMAGE/<image-name>:${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG}
docker push $CI_REGISTRY_IMAGE/<image-name>:${CI_PIPELINE_ID}${CI_COMMIT_REF_SLUG}
Ostensibly the fix for this issue is in the gitlab milestone for 12.8 but since our internal gitlab is still on 11.10 i can't test this.