尝试使用PowerShell将父链接添加到TFS任务 [英] Trying to use PowerShell to add a Parent Link to a TFS Task
本文介绍了尝试使用PowerShell将父链接添加到TFS任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我通过Powershell创建TFS任务时,我试图添加一个父链接.但是,我只能添加一个相关链接:
I am trying to add a parent link when I create TFS task via powershell. However, I am only able to add a related link:
function Create-New-WorkItem($projName, $taskType, $title, $state, $assignedTo, $iterationPath, $activity, $BLItem)
{
$tfs = Get-TfsServer
$ws = $tfs.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$proj = $ws.projects[$projName]
$workitem = $proj.workitemtypes[$taskType].newworkitem()
$workitem.open()
$workitem.title = $title
$workitem.state = $state
$workitem.fields["Assigned To"].value = $assignedTo
$workitem.iterationpath = $iterationPath
$workitem.fields["Activity"].value = $activity
$id = Get-Parent-Link $BLItem
$workitem.links.add($id.ID)
$workitem.close()
$workitem.save()
}
function Get-Parent-Link($backLogItemName)
{
$tfs = Get-TfsServer
$WIQL = @"
SELECT [System.Id]
FROM WorkItems
where [System.Title] = '$backLogItemName'
"@
return $tfs.wit.query($WIQL)
}
如何将链接添加为父链接而不是相关链接?
How can I add the link as a parent instead of a related?
推荐答案
经过反复试验,我终于找到了一种方法,可以将一个作为子级的新工作项目链接到父项目(即积压项目).
After some trial and error I finally found a way to accomplish linking a new work item as a child to a parent item i.e. backlog item.
$ws = $tfs.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$linkType = $ws.WorkItemLinkTypes[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreLinkTypeReferenceNames]::Hierarchy]
添加要将新的子工作项链接到的父项的工作项ID,并创建一个工作项链接对象:
Add the workitem id of the parent you want to link the new child workitem to and create a workitemlink object:
$link = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink($linkType.ReverseEnd, 1234)
然后您可以将链接添加到工作项:
You can then add the link to a workitem:
$workitem.WorkItemLinks.Add($link)
$workitem.save()
这篇关于尝试使用PowerShell将父链接添加到TFS任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文