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.
2
Answers
The ideas in @Daniel Mann answer are good, but I have meanwhile found a better solution for fire and forget.
Using this will lead to waiting for a response of True or False which can take time for some resources.
Now let's put this in a start job in the pipeline,
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.
Hosted agents have a maximum runtime of 60 minutes. You can use a self-hosted agent which doesn’t have this limitation.
Another alternative, and this is slightly hacky, would be to delete one item per pipeline run, then check if there are more to be deleted, and if so, use the REST APIs to re-trigger the pipeline. So if you have 5 items that need to be run, it would automatically run the pipeline 5 times.