VSTS Rest API查询Powershell中链接的工作项 [英] VSTS Rest API queries for linked work items in Powershell
问题描述
在 PowerShell
中使用VSTS的REST API,我想在VSTS团队项目上创建一个报告,其中包含特定迭代路径"下所有工作项的工作项链接关系的详细信息,并且区域路径".
Using REST APIs of VSTS in PowerShell
, I wanted to create a report on my VSTS Team Project which consists of the details of the Work Item Linking relationships of all workitems under particular "Iteration Path" and "Area Path".
例如: Epics→功能→UserStories
.由于Epics& amp;之间存在父母/子女关系.功能以及功能和功能之间用户故事.
Ex: Epics→Features→UserStories
. Since there are parent/child relationships between Epics & Features and also between Features & UserStories.
因此,输入将是 Iteration Path
和 Area Path
,相应的输出将是具有所有这些详细信息的报告(.csv或.xls)工作项及其关系.
So the input would be Iteration Path
and Area Path
, and the corresponding output would be a report (.csv or .xls) which has all the details of these workitems and their relationships.
有人可以让我知道如何在PowerShell中使用REST API来实现这一目标吗?
Could someone let me know on how to achieve this using REST APIs in PowerShell?
我编写了用于在团队项目中获取分层工作项的代码,但需要修改以基于给定的Iteration和Area路径来过滤列表.同样,在执行以下代码时,由于存在''",查询中的字符串比较会在power-shell中返回错误.
I wrote the code for getting the hierarchical workitems in a Team Project but need to modify to filter the the list based on a given Iteration and Area paths. Also when executing the below code, the string comparison in the query(due to presence of '') is returning an error in the power-shell.
错误::Invoke-RestMethod:{"count":1,"value":{"Message":"在解析值后,遇到意外字符:G.路径查询",第1行,位置163.\ r \ n}}
Error: Invoke-RestMethod : {"count":1,"value":{"Message":"After parsing a value an unexpected character was encountered: G. Path 'query', line 1, position 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
推荐答案
像这样修改部分代码:
$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)
"
$body = @{query=$query} | ConvertTo-Json
$result = Invoke-RestMethod -Uri $uri -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic $base64AuthInfo")} -Body $body
这篇关于VSTS Rest API查询Powershell中链接的工作项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!