1

I have a jenkins multi branch project, that builds on every commit and pushes the image to our private registry:

docker-reg:5000/<project>/<branch>:latest
docker-reg:5000/<project>/<branch>:<build-server>-<build-number>

How can I delete the labels in the docker registry in order to let the garbage collector kick in upon:

  • build gets orphaned after some time
    • remove <project>/<branch>:<build-server>-<build-number
  • branch gets merged and jenkins sub project gets automatically deleted
    • remove <project>/<branch>:latest

2 Answers 2

1

We have a script which we run periodicaly which scans our docker registry for orphaned items, and then deletes them.

Unfortunately, it requires multiple API calls to get all the data required, and then to delete each image. But basically, if an image hash is lacking a 'latest' tag or a tag that starts with 'v' it gets culled.

You could probably also try deleting based on last modified date.

We run this as a cron job in kubernetes, but you could just as easily run a script like this as a periodic jenkins job.

0

This is a very complicated issue for a few reasons:

  1. The biggest problem is Jenkins does not have any way of notifying you when a branch is deleted or a OR is merged. There are a lot of issues in Jenkin's jira, but from what I know - this one is the monitored one.

  2. You would somehow need to keep a record of all of the published tags.

Overall I don't see how you'd achieve this as it's simply not possible from Jenkin's side. It would be cool if somebody else has found a solution to this. I have looked for one a few times already without any luck.

2
  • I see, would this be possible in gitlab?
    – DaSteph
    Commented Aug 8, 2019 at 20:14
  • Unfortunately I don't use GitLab very much. Maybe you could hook into the Stop an environment.
    – tftd
    Commented Aug 9, 2019 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.