templates - 如何将子项分配给 TFS 模板中的产品待办事项列表项

标签 templates tfs

我们在一些产品积压项目(pbi)中有相同的任务,每次我们都必须创建pbi和任务以及相同的东西,只有一点点差异。因此,我们想要创建一个模板 pbi 和任务,我们做到了,但无法将任务分配给 pbi。当我们检查字段时,没有“父 ID”或类似的内容。

如何做到这一点?我也可以接受我们可以编写一个 powershell 脚本。

版本是版本16.131.27701.1

最佳答案

我们无法将关系添加到 TFS 工作项模板中,我们只能为工作项模板中的特定工作项类型设置可用字段的值。请参阅Use templates to add and update work items了解详情。

因此,我们无法将子项分配给 TFS 工作项模板中的 PBI。不过,我们可以通过 REST API ( Add a Link ) 分配子级。

例如:

PATCH http://server:8080/tfs/DefaultCollection/_apis/wit/workitems/111?api-version=4.0

Content-Type: application/json-patch+json

[
  {
    "op": "test",
    "path": "/rev",
    "value": 8
  },
  {
    "op": "add",
    "path": "/relations/-",
    "value": {
      "rel": "System.LinkTypes.Hierarchy-Forward",
      "url": "http://server:8080/tfs/DefaultCollection/{ProjectName or ID}/_apis/wit/workItems/129",
      "attributes": {
        "comment": "Add child link to PBI"
      }
    }
  }
]

您可以使用以下 PowerShell 脚本将多个子工作项分配给特定的父 PBI:

Param(
   [string]$baseurl = "http://server:8080/tfs/DefaultCollection",  
   [string]$projectName = "0511ScrumTFVC",
   [string]$PBI = "111",
   [string]$user = "Domain\user",
   [string]$token = "Password"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$uri = "$baseurl/_apis/wit/workitems/$($PBI)?api-version=4.0"

#For non-continuous child work item IDs
#$childs = (130,134,136)

#For Continuous child work item IDs
$childs = (130..134) #This will link child work item 130,131,132,134 to PBI 111

foreach ($child in $childs)
{

function CreateJsonBody
{
    $value = @"
[
  {
    "op": "test",
    "path": "/rev",
    "value": 8
  },
  {
    "op": "add",
    "path": "/relations/-",
    "value": {
      "rel": "System.LinkTypes.Hierarchy-Forward",
      "url": "$baseurl/$projectName/_apis/wit/workItems/$child",
      "attributes": {
        "comment": "Add child work itme $child to PBI $PBI"
      }
    }
  }
]

"@

 return $value
}

$json = CreateJsonBody
$response = Invoke-RestMethod -Uri $uri -Method PATCH -Body $json -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
}

关于templates - 如何将子项分配给 TFS 模板中的产品待办事项列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52813841/

相关文章:

c# - 如何以编程方式检查项目是否映射到 TFS 中?

c# - 使用 Windows 凭据以编程方式登录 TFS

错误; RPC失败;结果=22,HTTP 代码=401

c++ - union 作为模板化基类的部分特化

c++ - 将访问者模式与模板派生类一起使用

java - Team Foundation Server 构建的限制

visual-studio - 使用 Team Foundation Server 源代码管理回滚更改

c++ - 如何通过子类型列表创建指针 vector ?

C++ 通用节点类不会采用不同类型的节点

c++ - 侵入式数据结构中的成员钩子(Hook)与基本钩子(Hook)