在 PowerShell 中使用 WIQL(工作项查询语言),我想创建一个关于我的 VSTS 团队项目的报告,其中包含特定“迭代路径”和“区域路径”下所有工作项的工作项链接关系的详细信息。例如:史诗→功能→用户故事。由于史诗和功能之间以及功能和用户故事之间存在父/子关系。因此输入将是“迭代路径”和“区域路径”,相应的输出将是包含这些工作项及其关系的所有详细信息的报告(.csv 或 .xls)。有人可以告诉我如何在 PowerShell 中使用 WIQL 来实现这一目标吗?
1074 次
1 回答
1
简单示例:
#Load TFS PowerShell Snap-in
if((Get-PSSnapIn -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
}
#Load Reference Assemblies
$Tfs2015AssembliesPath="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer"
Add-Type -Path "$Tfs2015AssembliesPath\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "$Tfs2015AssembliesPath\Microsoft.TeamFoundation.Common.dll"
Add-Type -Path "$Tfs2015AssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Function GetWorkItems{
param([string]$teamProjectName,[string]$address)
$credentials = New-Object System.Net.NetworkCredential("[user name]", "[password]")
$tfsCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection((New-Object System.URI($address)))
$wis = $tfsCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
$wiqlQT="select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] from WorkItemLinks where (Source.[System.TeamProject] = @project and Source.[System.WorkItemType] = 'Epic' and Source.[System.State] <> '' and Source.[System.AreaPath] = 'Agile2015Starain' and Source.[System.IterationPath] = 'Agile2015Starain') and ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') and (Target.[System.TeamProject] = @project and Target.[System.WorkItemType] <> '') mode (Recursive)"
$variableValues=@{}
$variableValues.Add("project", $teamProjectName)
$query=New-Object Microsoft.TeamFoundation.WorkItemTracking.Client.Query($wis,$wiqlQT,$variableValues)
$witCollection=$query.RunLinkQuery()
#logical to save data to excel or csv
$wits=New-Object "System.Collections.Generic.List[Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem]"
$title=""
$id=0
Foreach($witItem in $witCollection)
{
$id=$witItem.SourceId
if($id -gt 0)
{
$parentWorkItem = $wits | where {$_['ID'] -eq $id}
$t = $parentWorkItem.Title;
}
$currentWorkItem = $wis.GetWorkItem($witItem.TargetId);
$t = $currentWorkItem.Title;
$wits.Add($currentWorkItem);
}
}
GetWorkItems "Agile2015Starain" "https://[your vsts name].visualstudio.com"
于 2016-11-09T05:24:25.023 回答