Automatic Clean Up Of Deployment Logs In Azure

Introduction

As we know, in order to work with Azure resources we have to deploy different services to Azure. One limitation of azure resource deployment is that it only allows 800 deployment logs. After this threshold, we can't proceed with the resource deployment.

How to automate the clean-up of deployment logs?

We can create an Azure DevOps Release Pipeline with Azure PowerShell task and schedule this pipeline to run this task so deployment logs will be deleted automatically and your deployment will never be blocked due to limits.

Azure Powershell Script

$thresold=100
$resourceGroup = 'xxxx-d-rg'
Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroup| Select-Object -Skip $thresold| Remove-AzResourceGroupDeployment

Here, threshold = integer number, the script will delete all deployment logs of more than 100.

resource group = resource group name.

Conclusion

We can save a lot of time by implementing this automation instead of manually deleting the deployment logs.