How to recreate Azure DevOps elastic pool with new image

426 Views Asked by At

Basically I am working on revamping a pipeline we have that generates an elastic pool in Azure DevOps. I keep running into issues because we are relying on the Azure API. The pipeline first seems to remove Queues that are attached to the elastic pool, and then attempted to do a POST to create a new elastic pool, but when I run it with my updated packer image (with windows 2022) I keep running into the same error: ##[error]Agent pool already exists.

I can manually delete the elastic pool through the UI and re-run the pipeline, but then it fails at a different step that is calling the cmdlet: Update-AzVmssInstance

So my block/question is: is there a way to properly delete + recreate an elastic pool in Azure DevOps or somehow overwrite an existing one with the new machine image using the APIs (https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/elasticpools/create?view=azure-devops-rest-7.1).

2

There are 2 best solutions below

0
milesb On

I encountered something similar to this with the UI recently. I had deleted an existing elastic pool and attempted to recreate it, it also told me that the agent pool with identifier x already exists.

This may not be useful for your situation - but I tried creating it again with the same parameters and it worked.

0
WojBronx On

To delete and recreate elastic pool we use both pools and elasticpools APIs. This is because, surprisingly, the elasticpools API doesn't have delete endpoint. The approach which we use is not documented (in general, the topic of automation VMSS agent pools if poorly documented), but we used it hundreds of times successfully, and there is no other automatic solution.

Our solution:

However, last week it failed on two agent pools and now we are in discussion with Microsoft about how to remove them. The thing is that after deletion it disappeared from DevOps UI and is not found by GET https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolId}?api-version=7.1-preview.1 but it is found by GET https://dev.azure.com/{organization}/_apis/distributedtask/elasticpools/{poolId}?api-version=7.1-preview.1 The result is that POST elasticpools throws exception saying that the agent pool exists.