【问题标题】:Azure DevOps Services REST API - Batch Update of Work ItemsAzure DevOps Services REST API - 工作项的批量更新
【发布时间】:2021-12-31 21:36:29
【问题描述】:
【问题讨论】:
标签:
azure-devops
azure-devops-rest-api
azure-devops-services
【解决方案1】:
您可以参考旧版文档:Work Item Batch Update
另一种方法是编写脚本以循环调用Work Items - Update REST API 以根据您的要求更新工作项。
以下是使用 PowerShell 更新特定工作项的示例,供您参考:
Param(
[string]$baseurl = "https://dev.azure.com/{organization}",
[string]$projectName = "Project",
[string]$workitemid = "124",
[string]$user = "user",
[string]$token = "xxxxx PAT token here"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
write-host $WorkitemType
function CreateJsonBody
{
$value = @"
[
{
"op": "test",
"path": "/rev",
"value": 2
},
{
"op": "add",
"path": "/fields/System.State",
"value": "New"
}
]
"@
return $value
}
$json = CreateJsonBody
$uri = "$baseurl/$projectName/_apis/wit/workitems/$($workitemid)?api-version=6.0"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}