TFS 2018 Create agent pool programatically

前端 未结 2 1234
栀梦
栀梦 2021-01-17 04:00

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

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 04:18

    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:///_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.

提交回复
热议问题