gpt4 book ai didi

azure-devops-rest-api - 使用 REST API 将构建链接添加到工作项

转载 作者:行者123 更新时间:2023-12-03 08:48:51 25 4
gpt4 key购买 nike

我有一个由另一个构建触发的构建。触发构建具有与其链接的工作项。为了获得更好的可见性,我想将链接到触发构建的所有工作项也链接到触发的构建。我已经准备好提取工作项列表的所有内容,但我找不到使用 REST API 将工作项链接到构建的方法尝试使用工作项 - 更新添加链接选项 https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/update?view=azure-devops-rest-5.1#add-a-link

工作项关系类型 - 列表返回: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20item%20relation%20types/list?view=azure-devops-rest-5.1

System.LinkTypes.Remote.Dependency-Forward
System.LinkTypes.Remote.Dependency-Reverse
System.LinkTypes.Duplicate-Forward
System.LinkTypes.Duplicate-Reverse
Microsoft.VSTS.TestCase.SharedParameterReferencedBy-Forward
Microsoft.VSTS.TestCase.SharedParameterReferencedBy-Reverse
Microsoft.VSTS.Common.Affects-Forward
Microsoft.VSTS.Common.Affects-Reverse
Microsoft.VSTS.TestCase.SharedStepReferencedBy-Forward
Microsoft.VSTS.TestCase.SharedStepReferencedBy-Reverse
Microsoft.VSTS.Common.TestedBy-Forward
Microsoft.VSTS.Common.TestedBy-Reverse
System.LinkTypes.Dependency-Forward
System.LinkTypes.Dependency-Reverse
System.LinkTypes.Hierarchy-Forward
System.LinkTypes.Hierarchy-Reverse
System.LinkTypes.Related
System.LinkTypes.Remote.Related
AttachedFile
Hyperlink
ArtifactLink

除了最后3个,似乎都是WI与WI的关系。如何添加构建链接?

最佳答案

正确的关系类型是 ArtifactLink。

我在管道中使用了以下 powershell 代码来创建这些链接:

$personalToken = "<insert personal token here>"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
$header = @{authorization = "Basic $token"}

$buildId = $(Build.BuildId)
$azureDevOpsOrg = "<insert your organization name here>"
$projectName = "<insert your project name here>"

$buildWorkItemsUrl = "https://dev.azure.com/${azureDevOpsOrg}/${projectName}/_apis/build/builds/${buildId}/workitems?api-version=5.0"

$body = "[
{
""op"": ""add"",
""path"": ""/relations/-"",
""value"": {
""rel"": ""ArtifactLink"",
""url"": ""vstfs:///Build/Build/${buildId}"",
""attributes"": {
""name"": ""Integrated in build""
}
}
}
]"

$workItems = Invoke-RestMethod -Uri $buildWorkItemsUrl -Method Get -ContentType "application/json" -Headers $header

$workItems.value | ForEach-Object {
$workItemId = $_.id
Write-Host $workItemId
$updateWorkItemurl = "https://dev.azure.com/${azureDevOpsOrg}/${projectName}/_apis/wit/workitems/${workItemId}?api-version=6.0"
Write-Host $updateWorkItemurl
Invoke-RestMethod -Uri $updateWorkItemurl -Method Patch -ContentType "application/json-patch+json" -Headers $header -Body $body
}

关于azure-devops-rest-api - 使用 REST API 将构建链接添加到工作项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60184540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com