如何以编程方式更改分配给任务的用户?

时间:2019-03-13 09:33:26

标签: api tfs command-line-interface

在TFS中,如何使用API​​或命令行更改分配给任务的用户?
谢谢。

1 个答案:

答案 0 :(得分:1)

您可以使用Work Items - Update Rest API更新任何工作项字段。

PowerShell示例:

  $collectionUrl = "http://{tfs-url}:8080/tfs/{collection}"
  $workItemId = "1"
  $byPass = "true"
  $url = "$collectionUrl/_apis/wit/workitems/$workItemId?bypassRules=$($byPass)&api-version=3.0"

  #the "op : add" is also repleace existing value
  $body = '[
           {             
             "op":"add",
             "path":"/fields/System.AssignedTo",
             "value":"User Name"              
           }
           ]'

  try
  {
     Invoke-RestMethod -Method Patch -UseDefaultCredentials -Uri $url -Body $body -ContentType application/json-patch+json
     Write-Host "Change work item $workItemId" -ForegroundColor Green
  }
  catch
  {
     Write-Host $_ -ForegroundColor Red
  }