VSTS工作项通过REST API列出 [英] VSTS work items list through REST API

查看:74
本文介绍了VSTS工作项通过REST API列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用REST API从VSTS获取工作项列表?

How can I get a list of work items from VSTS using the REST API?

根据文档ids参数是可选的,但是当我省略它时,会出现一个404错误. 如果添加ids参数,则可以获取项目.

According to the documentation, the ids parameter is optional, but when I omit it I get a 404 error. If I add the ids parameter, I can get the items.

失败请求:
GET https://{account}.visualstudio.com/DefaultCollection/_apis/wit/workitems?api-version=1.0

Failing request:
GET https://{account}.visualstudio.com/DefaultCollection/_apis/wit/workitems?api-version=1.0

成功请求:
GET https://{account}.visualstudio.com/DefaultCollection/_apis/wit/workitems?ids=252&api-version=1.0

Succeeding request:
GET https://{account}.visualstudio.com/DefaultCollection/_apis/wit/workitems?ids=252&api-version=1.0

两者的身份验证相同.

要解决的完整问题是:获取特定VSTS项目中的所有功能

The complete problem to solve is: get all features in a specific VSTS project

推荐答案

关键是使用API​​的 WIQL 部分,而不是工作项. 例如,要获取某种类型的工作项目的清单,请使用以下命令: https://www.visualstudio. com/en-us/docs/integrate/api/wit/wiql#a-flat-query

The key is to use WIQL part of the API, not the Work Item one. For example to get a flat list of Work Items of some type use this: https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql#a-flat-query

PowerShell中的示例(显示所有处于关闭"状态的用户故事):

Example in PowerShell (shows all User Stories in Closed state):

    # using env vars passed from VSTS build
    $collectionuri = $Env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI
    $token = $Env:SYSTEM_ACCESSTOKEN # need to configure build to allow passing OAuth tokens

    $basicAuth = "{0}:{1}"-f "ivan-the-terrible", $token
    $basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth)
    $basicAuth = [System.Convert]::ToBase64String($basicAuth)
    $headers = @{Authorization=("Basic {0}"-f $basicAuth)}

    $WorkItemType = 'User Story'

    $url = $collectionuri + 'DefaultCollection/_apis/wit/wiql?api-version=1.0'

    $WIQL_query = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = '" + $WorkItemType + "' AND [State] = 'Closed' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
    $body = @{ query = $WIQL_query }
    $bodyJson=@($body) | ConvertTo-Json

    $response = Invoke-RestMethod -Uri $url -headers $headers -Method Post -ContentType "application/json" -Body $bodyJson

    $workitems = $response.workItems

    Write-Host "Found" $workitems.Count "work items of type:" $WorkItemType

这篇关于VSTS工作项通过REST API列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆