0

Is it possible to create an Agent Pool in TFS 2018 programatically, preferably via PowerShell? I cannot find anything like that in REST API.

riQQ
  • 9,878
  • 7
  • 49
  • 66
Petr
  • 182
  • 1
  • 4
  • 18

2 Answers2

0

I don't know why it's not well-documented, but this just worked for me against VSTS:

$token = 'myPAT'
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((":{0}" -f $token)))

$uri = 'https://<url>/_apis/distributedtask/pools?api-version=4.1-preview.1'
$result = Invoke-RestMethod -Uri $uri -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} `
-Body (ConvertTo-Json @{name = 'foo'; autoProvision = $true})

I just looked at the REST API used in the web portal to create an agent pool and copied it; if the API version isn't the same in TFS 2018 as it is in VSTS, you can do the same thing to find the correct version to use.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
0

The REST API of TFS has an undocumented portion that deals with app pools: _apis/distributedtask/pools. For example:

Get agent pools (Request method: Get):

http://[TFS URL]/_apis/distributedtask/pools?api-version=x.x-preview.1`

api-version should match your TFS version

You could open up Chrome/IE Network inspector and found that the API calls for create agent pool action. How to do this please refer:

Finally, you just need to call REST API through PowerShell, take a look at this answer.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Thank you. I accepted @Daniel Mann answer because it was basically the same. Do you please have any idea why is this part undocumented? Is it likely to change in future versions of TFS? – Petr Apr 03 '18 at 10:31
  • @ppa Sorry, have no idea about this. *Is it likely to change in future versions of TFS?* Haven't heard it. However, even it's not well-documented, but you could still use that. And you could also use Network inspector to verify the API. – PatrickLu-MSFT Apr 03 '18 at 15:18