使用 powershell 将工作项与当前构建相关联并将文件附加到工作项

Associate Work Item With Current Build and attach file to work item using powershell

如何使用 powershell 将工作项与当前构建相关联并将文件 json 附加到工作项?我使用 Azure Devops 服务并且我有这个脚本:

$connectionToken="<my_token>"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))

$url= 'https://dev.azure.com/{organization}/{project_name}/_apis/wit/workitems/$Task?api-version=6.0'

$body=@"
  [
    {
      "op": "add",
      "path": "/fields/System.WorkItemType",
      "value": "Risk"
    },
    {
      "op": "add",
      "path": "/fields/System.Title",
      "value": "Test"
    },
    {
      "op": "add",
      "path": "/fields/System.Tags",
      "value": "test"
    },
    {
      "op": "add",
      "path": "/fields/System.Description",
      "value": "test"
    },
    {
      "op": "add",
      "path": "/fields/Mitigation",
      "value": "test"
    },
    {
      "op": "add",
      "path": "/fields/Risk",
      "value": "1 - High"
    },
    {
      "op": "add",
      "path": "/fields/Microsoft.VSTS.Build.IntegrationBuild",
      "value":  `"{value}`"}]"
    }
 ]
"@

Write-Host "$url"
$response= Invoke-RestMethod -Uri $url  -ContentType "application/json-patch+json" -Body $body -headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST

但是 link 与当前构建的关联不起作用,我无法找到我需要添加的内容以将 json 文件附加到我的 Azure Pipeline

中的工作项
  1. 要附加文件,您必须上传文件 (Upload a text file) and then add the link to your work item (Add an attachment):
  2. Microsoft.VSTS.Build.IntegrationBuild 只是一个没有任何 link 的字段。您必须添加 ArtifactLink link 和 Integrated in build 类型: