我正在研究通过Azure DevOps中的API将工作项附加到合并请求的方法。
我已尝试使用以下方法,但未成功标记工作项。
$requestUri = "https://dev.azure.com/$org/$project/_apis/wit/workitems/12345?api-version=4.1"
$prapi1 = "https://dev.azure.com/$org/$project/_apis/git/repositories/$repo/pullRequests/12345"
$json = @"
[ {
"op": "add",
"path": "/relations/-",
"value": {
"rel": "ArtifactLink",
"url": "$pr",
"attributes": { "name": "pull request" }
}
} ]
"@
$response = Invoke-RestMethod -Uri $requestUri -Headers $headers -ContentType "application/json-patch+json" -Method Patch -Body $json
字符串
但是,当使用指定的API时,我遇到一个错误,指示我:
{"$id”:“1”,“innerException”:null,“message”:“无效的资源链接目标:'https://dev.azure.com/org/project/_apis/git/repositories/repo/pullRequests/12345'.",“typeName”:“Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemResourceLinkException,Microsoft.TeamFoundation.WorkItemTracking.Server”,“typeKey”:“WorkItemResourceLinkException”,“errorCode”:0,“eventId”:3200}
1条答案
按热度按时间agxfikkp1#
根据您的脚本示例,问题的原因是pr url不正确。
正确格式:
vstfs:///Git/PullRequestId/{projectId}/{repositoryId}/{pullRequestId}
您可以在Rest API中获取Pull Request URL:Pull Requests - Get Pull Request
它将在响应中显示artifactId。
举例来说:
x1c 0d1x的数据
以下是PowerShell示例:
字符串