2016-11-08 50 views
-1

在PowerShell中使用WIQL(工作項查詢語言)時,我想創建一個關於我的VSTS團隊項目的報告,其中包含所有工作項的工作項鍊接關係的詳細信息「迭代路徑」和「區域路徑」。例如:Epics→功能→用戶故事。由於Epics &功能之間以及功能& UserStories之間存在父母/子女關係。因此,輸入將是「迭代路徑」和「區域路徑」,相應的輸出將是一個報告(.csv或.xls),其中包含這些工作項及其關係的所有詳細信息。有人能告訴我如何在PowerShell中使用WIQL來實現這一點嗎?在PowerShell中鏈接的工作項上的VSTS WIQL查詢

+0

你解決這個問題,我的解決方案? –

回答

0

簡單的例子:

#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)" 
     [email protected]{} 
     $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" 
相關問題