Lets say you have Gitlab CI defined that generates docker images on merge request. This is great because it lets people review your work in a consistent environment. The problem is all those image tags from branches hang around in the registry and clutter things up. Wouldn't it be great if you could remove those tags as apart of the CI when you merge to master?
When merging a branch to gitlab it automatically provides a merge title "Merge branch 'branch-name' into 'master'." During the master CI pipeline we can parse out the branch name from the commit and use that to remove any tagged images in the form gitlab.kitware.com:4567/group/project/container:branch-name
.
There are a few sticking points we have to negotiate. In order to use a reasonable tag name when generating the merge request image tag we use the $CI_COMMIT_REF_SLUG
which is a url friendly conversion of the branch name (e.g. "dev/feature/branch-name" becomes "def-feature-branch-name"). The script parses out 'dev/feature