I use Azure DevOps pipelines to create and destroy resources in Azure.
When destroying resources, I use Remove-AzResourceGroup
and it works fine.
The issue is that I have multiple Container App Environments, and when deleting those, it takes at least 20-25 minutes, 3x of those will take more than an hour leading to a long-running pipeline and in most cases time-out, so I need to re-run the pipeline 2-3 time until the deletation is done. Even though I have set the job timeoutInMinutes
to 0
which means theoretically infinite but still times out after when it reaches approx 60 min.
Is there a way to fire the delete process and forget without waiting?
Or an alternative/creative solution so I can overcome the long waiting running job.
The ideas in @Daniel Mann answer are good, but I have meanwhile found a better solution for fire and forget. The part about trying to run the pipeline via the rest API call part from the other answer can be combined with my answer here as well. This will help to delete dependency resources that can not be deleted until other resources it depends on are deleted
I did use the following to delete multiple resources from a loop which will lead to waiting for a response of True or False which can take time for some resources and timeout the pipeline.
Remove-AzResourceGroup -Name "rg-name" -Force
Now let's put this in a Start-Job
in the pipeline,
$name = 'rg-name'
$sb = [scriptblock]::Create("Remove-AzResourceGroup -Name '$name' -Force")
Start-Job -ScriptBlock $sb
The nice thing here, it will initiate a removal process but does not need to wait. Of course, when the agent is done, the job will be disposed of, but the removal process is already initiated. This way I have solved the issue of waiting time.
I put the code snippet in a loop of the resources I want to delete.
Snapshot from azdo
Before the change, it took more than 60 min for 3 attempts
After the new way, it took around 7 minutes