2016-11-08 67 views
-1

使用中VSTS的REST API,我想創建一個關於VSTS團隊項目的報告,其中包含所有工作項的工作項鍊接關係的詳細信息,在特定的「迭代路徑「和」區域路徑「。VSTS Rest API對Powershell中鏈接工作項的API查詢

例如:Epics→Features→UserStories。由於Epics &功能之間以及功能& UserStories之間存在父母/子女關係。

因此,輸入將是Iteration PathArea Path,相應的輸出將是一個包含這些工作項及其關係的所有細節的報告(.csv或.xls)。

有人能告訴我如何在PowerShell中使用REST API來實現這一點嗎?

我編寫了用於在團隊項目中獲取分層工作項的代碼,但需要修改以基於給定的迭代和區域路徑來過濾列表。 另外,當執行下面的代碼時,查詢中的字符串比較(由於'')的存在會在power-shell中返回一個錯誤。

錯誤:調用-RestMethod:{ 「計數」:1, 「值」:{ 「消息」:「解析遇到意外的字符的值後:G. 路徑 '查詢',第1行,位置163 \ r \ n「}}你的代碼是這樣的

$vstsAccount = "xxxx" 
$projectName = "xxxx" 
$user = "xxxx" 
$token = "xxxx" 

# Base64-encodes the Personal Access Token (PAT) appropriately 
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token))) 

# Construct the REST URL to obtain Build ID 
$uri = "https://$($vstsAccount).visualstudio.com/$($projectName)/_apis/wit/wiql?api-version=1.0" 

$body = "{'query': 'Select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] From WorkItemLinks WHERE 
((Source.[System.TeamProject] = '$projectName' and Source.[System.State] <> 'Removed') and (Source.[System.WorkItemType] = 'Epic') and 
([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') and (Target.[System.WorkItemType] = 'UserStory') mode(Recursive)'}" 

# Invoke the REST call and capture the results (notice this uses the POST method) 
$result = Invoke-RestMethod -Uri $uri -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body 
+0

它看起來並不像你給這是一個嘗試做基本調查,甚至自己呢?有人不太可能爲您發佈完整的解決方案。你如何給它一個自己去,並回來填補空白的幫助? –

+0

您是否使用我的解決方案解決了問題? –

回答

0

修改部分:

$body = @{query="Select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] From WorkItemLinks WHERE 
    (Source.[System.TeamProject] = '$projectName' and Source.[System.State] <> 'Removed') and (Source.[System.WorkItemType] = 'Epic') and 
    ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') and (Target.[System.WorkItemType] = 'UserStory') mode (Recursive)"} 
    [email protected]($body) | ConvertTo-Json 
    $result = Invoke-RestMethod -Uri $uri -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $bodyJson 
+0

@ starain ..感謝您的信息。 – Srini33

+0

@ Srini33如果我的答案解決了您的問題,您可以將其標記爲答案。 –