如何使用REST API更新任务组

问题描述 投票:0回答:1

假设我正在尝试更新任务组描述。

  1. 我通过get请求获得所有任务组GET https://dev.azure.com/{organization}/{project}/_apis/distributedtask/taskgroups?api-version=6.0-preview.1
  2. 我按名称过滤并获取ID。例如。 aaabbbcc-abcd-ae12-917d-97f1935b1542
  3. 获得ID后,我使用PUT https://dev.azure.com/{organization}/{project}/_apis/distributedtask/taskgroups/aaabbbcc-abcd-ae12-917d-97f1935b1542?api-version=6.0-preview.1像这样的JSON主体
    {
    "description": "this is the new description",
    "id": "aaabbbcc-abcd-ae12-917d-97f1935b1542"
    }
    

但是最后一步不起作用。我会收到以下错误:

{
    "$id": "1",
    "innerException": null,
    "message": "Task group aaabbbcc-abcd-ae12-917d-97f1935b1542 not found.",
    "typeName": "Microsoft.TeamFoundation.DistributedTask.WebApi.MetaTaskDefinitionNotFoundException, Microsoft.TeamFoundation.DistributedTask.WebApi",
    "typeKey": "MetaTaskDefinitionNotFoundException",
    "errorCode": 0,
    "eventId": 3000
}

我在做什么错?

azure-devops azure-devops-rest-api
1个回答
0
投票
最佳方法是使用GET API中提供的任务组,并在此处更改描述,然后将其转换为JSON并通过PUT API发送所有对象。

例如-在PowerShell中:

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,"YOUR-PAT"))) $headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)} $url = "https://dev.azure.com/{organization}/{project}/_apis/distributedtask/taskgroups?api-version=6.0-preview.1" $taskGroups= Invoke-RestMethod -Method Get -Uri $url -Headers $headers -ContentType 'application/json' $taskGroups.value[0].description = "test" $json = $taskGroups.value[0] | ConvertTo-Json -Depth 10 $response = Invoke-RestMethod -Method Put -Uri $url -Headers $headers -ContentType 'application/json' -Body $json

© www.soinside.com 2019 - 2024. All rights reserved.