1
votes

I'm trying to create an agent pool (Azure devops Server) using powershell and invoke-restmethod. To do this I'm using the reference below to try a build up a correct json request body. https://docs.microsoft.com/en-us/rest/api/azure/devops/distributedtask/pools/add?view=azure-devops-rest-5.1 All basics in place (credentials etc - I have successfully run other tasks using other uris) Many attempts at finding the correct body, all pretty much with the same result, latest example below;

$requestBodyAgentPool = '{
    "Id": "3"
    "name": "Testpool",
    "isHosted": $false,
    "autoSize": $false,
    "poolType": "automation",
    "isLegacy": $false
}'

Using the following (verified the uri and credentials by running a GET)

$uriPool = "http://localhost/DefaultCollection/_apis/distributedtask/pools?api-version=5.1"

Invoke-RestMethod -Uri $uriPool -Method POST -ContentType 'application/json' -Body $requestBodyAgentPool -Credential $cred

Fails with below which to me means the parameter id is null.

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: pool.Name","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}

I have a feeling this is just my inexperience with coding terms and reading the reference documentation but it is not clear to me if the format is wrong or I'm missing/wrong format a mandatory parameter (id or name?)

1

1 Answers

0
votes

Suggest you could use some UI tool such as Postman to verify if you are able to run same Rest API. This will help you narrow down the issue.

{
"name": "{poolname}",
"autoProvision": $true
}

The request body should be a json format. Try to explicitly add ConvertTo-Json for your post body.

More details take a look at Daniel's reply in this link: TFS 2018 Create agent pool programatically