PowerShell 中链接工作项的 VSTS WIQL 查询
VSTS WIQL queries on linked work items in PowerShell
在 PowerShell 中使用 WIQL(工作项查询语言),我想创建一份关于我的 VSTS 团队项目的报告,其中包含特定 "Iteration Path" 和 [ 下所有工作项的工作项链接关系的详细信息=13=]。例如:Epics→Features→UserStories。由于 Epics 和 Features 之间以及 Features 和 UserStories 之间存在 parent/child 关系。因此输入将是 "Iteration Path" 和 "Area Path",相应的输出将是一份报告(.csv 或 .xls),其中包含这些工作项及其关系的所有详细信息。有人可以让我知道如何在 PowerShell 中使用 WIQL 实现此目的吗?
简单示例:
#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"
在 PowerShell 中使用 WIQL(工作项查询语言),我想创建一份关于我的 VSTS 团队项目的报告,其中包含特定 "Iteration Path" 和 [ 下所有工作项的工作项链接关系的详细信息=13=]。例如:Epics→Features→UserStories。由于 Epics 和 Features 之间以及 Features 和 UserStories 之间存在 parent/child 关系。因此输入将是 "Iteration Path" 和 "Area Path",相应的输出将是一份报告(.csv 或 .xls),其中包含这些工作项及其关系的所有详细信息。有人可以让我知道如何在 PowerShell 中使用 WIQL 实现此目的吗?
简单示例:
#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"