【问题标题】:How to delete a work item relation (parent) from a child task work item via HTTP request to azure devops?如何通过 HTTP 请求从子任务工作项中删除工作项关系(父级)到 azure devops?
【发布时间】:2021-03-13 14:07:04
【问题描述】:

在 Azure Devops 中,我有一个任务工作项,它有一个与其链接的父工作项。我知道如何通过 Azure Devops 做到这一点。但是,我想知道如何通过对 azure devops 的 HTTP 请求从子任务工作项中删除父任务关系?

【问题讨论】:

    标签: azure azure-devops-rest-api


    【解决方案1】:

    您可以使用Work Items - Updaterest api从子任务中删除父任务关系。

    首先你需要检查父任务在子任务的关系数组列表中的索引。使用Work Items - Get Work Item rest api 并指定$expand=Relations 参数以将关系包含在结果中。请参阅下面的 powershell 脚本示例:

    $token="PAT"
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
    $uri = "https://dev.azure.com/ORG/PROJ/_apis/wit/workitems/9?`$expand=Relations&api-version=6.1-preview.3"
    $invRestMethParams = @{
        
        Uri = $uri
        Method = 'get'
        Headers= @{Authorization=("Basic {0}" -f $base64AuthInfo)}
      }
    $res= Invoke-RestMethod @invRestMethParams
    
    $res.relations
    

    结果:

    在上面的例子中,父任务被列为子任务的关系数组列表中的第一个元素。所以父任务索引为0。

    然后使用 Work Items - Update rest api 移除父任务关系。

    请求正文:

    $body='[
     {
        "op": "remove",
        "path": "/relations/0"  #parent task index is 0
        
      }
     ]'
    

    请参见下面的 powershell 脚本示例:

    $token="PAT"
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
    $uri = "https://dev.azure.com/ORG/PROJ/_apis/wit/workitems/9?`$expand=Relations&api-version=6.1-preview.3"
    
    $body='[
         {
            "op": "remove",
            "path": "/relations/0"  #parent task index is 0
            
          }
         ]'
    
    $invRestMethParams = @{
          Uri = $uri
          Method = 'PATCH'
          ContentType = 'application/json-patch+json'
          Headers= @{Authorization=("Basic {0}" -f $base64AuthInfo)}
          Body=$body
        }
    Invoke-RestMethod @invRestMethParams
        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 2020-01-29
      • 1970-01-01
      • 2021-11-21
      • 2020-06-28
      • 2020-06-11
      • 1970-01-01
      相关资源
      最近更新 更多