Work with an additional stage in the DevOps release pipeline for cleaning up

This the second part of the Azure DevOps post to pass information through variables between pipelines. It deals with cleaning up after image creation. Find the first part here:

Pass variables form build pipelines to release pipelines

It is important to keep the Azure container registry storing the Docker images clean. On the one hand, for overview purposes and on the other hand because you are billed based on the number of stored images in the registry. So, keeping old images for already integrated features doesn’t make sense.

You could do that manually, but that’s an effort. Automated clean up is available in the more expensive premium tier, but that helps at the moment only for untagged images.

Another approach for automatic clean up is to use an additional pipeline stage which is triggered by the stage before, which does the work of creating the images.

Again, a powershell task comes into play for the correct image to clean up. It holds some individual logic for decision in the origin case, if the information stored in pipeline var is enough for your case, the task is not needed.

With that data, Azure PowerShell Tasks configured with the correct Service Connection for your Azure resources can do the clean up work. For example delete databases and the Docker images only valid for a specific feature.

One thing I also tried was to work with an additional agentless Job after image creation. I inserted a manual intervention step to pause the release pipe. After hitting resume, I inserted the clean up scripts as shown above. That worked fine, but had a little hook – the following Release pipe, triggered by another pull request from another feature stays in queue mode until you resume (and therefore delete) the other pipe. As parallel testing of the images was needed, this was not a proper solution.

Leave a comment

Your email address will not be published. Required fields are marked *