【问题标题】:VSTS Rest API queries for linked work items in PowershellVSTS Rest API 查询 Powershell 中链接的工作项
【发布时间】:2016-11-08 04:16:48
【问题描述】:

PowerShell 中使用 VSTS 的 REST API,我想创建一份关于我的 VSTS 团队项目的报告,其中包含特定“迭代路径”和“区域路径”下所有工作项的工作项链接关系的详细信息。

例如:Epics→Features→UserStories。由于史诗和功能之间以及功能和用户故事之间存在父/子关系。

因此输入将是Iteration PathArea Path,相应的输出将是包含这些工作项及其关系的所有详细信息的报告(.csv 或 .xls)。

有人可以告诉我如何在 PowerShell 中使用 REST API 来实现这一点吗?

我编写了用于在团队项目中获取分层工作项的代码,但需要修改以根据给定的迭代和区域路径过滤列表。 此外,在执行以下代码时,查询中的字符串比较(由于存在 '')在 power-shell 中返回错误。

错误: Invoke-RestMethod : {"count":1,"value":{"Message":"解析值后遇到意外字符: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

【问题讨论】:

  • 您似乎没有完成基本调查,甚至没有亲自尝试过?有人不太可能为您发布完整的解决方案。您自己试一试,然后回帖寻求帮助,如何填空?
  • 你用我的解决方案解决了这个问题吗?

标签: excel powershell azure-devops


【解决方案1】:

像这样修改部分代码:

$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

【讨论】:

  • @Srini33 如果我的回答解决了您的问题,您可以将其标记为答案。
猜你喜欢
  • 1970-01-01
  • 2019-03-11
  • 2019-02-06
  • 2010-11-25
  • 1970-01-01
  • 1970-01-01
  • 2018-10-28
  • 1970-01-01
  • 2012-05-31
相关资源
最近更新 更多