我正在寻找一些工具来查询团队冲刺的当前工作项目。对于一个组织,项目和团队,我不确定该怎么做。通过执行此调用,我似乎可以得到当前的迭代:
https://dev.azure.com/ {org} / {project} / {{team} / _ apis / work / teamsettings / iterations?$ timeframe = current&api-version = 5.1
它返回如下内容:
{
"count": 1,
"value": [
{
"id": "8c15e886-ece7-49ce-ab5a-4090aefb5ce2",
"name": "Sprint 1",
"path": "Red Kitten Matrix\\Sprint 1",
"attributes": {
"startDate": null,
"finishDate": null,
"timeFrame": "current"
},
"url": "https://dev.azure.com/chrisdevopsprojects/e8d05711-3014-4ba7-82b7-ab6829c455dc/aed68f47-9035-4af5-9b0d-b0c19b4e9e9e/_apis/work/teamsettings/iterations/8c15e886-ece7-49ce-ab5a-4090aefb5ce2"
}
]
}
所以我可以找到当前团队的sprint,但是如何返回其中的所有sprint工作项和任务?
我在这里看不到任何信息:
谢谢!
编辑:
因此,我发现了一个工作项查询语言(WIQL ...为什么不去猜测)查询,当我在UI的devop中调用它时,该查询就可以工作,并且可以通过其余的API进行工作,但这会导致我发出一堆ajax请求以将所有内容都撤回。请让我知道是否有更简单的方法来获取此信息。
这是我的WIQL:
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State],
[System.Tags]
FROM workitemLinks
WHERE
(
[Source].[System.TeamProject] = @project
AND [Source].[System.WorkItemType] <> 'Task'
AND [Source].[System.State] <> ''
AND [Source].[System.IterationPath] = @currentIteration('[Red Kitten Matrix]\Red Kitten Matrix Team <id:aed68f47-9035-4af5-9b0d-b0c19b4e9e9e>')
)
AND (
[Target].[System.TeamProject] = @project
AND [Target].[System.WorkItemType] <> ''
)
ORDER BY [System.Id]
MODE (MayContain)
但是当我尝试通过此端点通过api进行操作时: https://dev.azure.com/chrisdevopsprojects/Red%20Kitten%20Matrix/Red%20Kitten%20Matrix%20Team/_apis/wit/wiql?api-version=5.1
发布此正文:
{
"query": "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM workitemLinks WHERE ( [Source].[System.TeamProject] = @project AND [Source].[System.WorkItemType] <> 'Task' AND [Source].[System.State] <> '' AND [Source].[System.IterationPath] = @currentIteration('[Red Kitten Matrix]\\Red Kitten Matrix Team')) AND ([Target].[System.TeamProject] = @project AND [Target].[System.WorkItemType] <> '' ) ORDER BY [System.Id] MODE (MayContain)"
}
我得到的响应形状如下:
{
"queryType": "oneHop",
"queryResultType": "workItemLink",
"asOf": "2020-04-28T03:00:48.353Z",
"columns": [
{
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
{
"referenceName": "System.WorkItemType",
"name": "Work Item Type",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.WorkItemType"
},
{
"referenceName": "System.Title",
"name": "Title",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Title"
},
{
"referenceName": "System.AssignedTo",
"name": "Assigned To",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.AssignedTo"
},
{
"referenceName": "System.State",
"name": "State",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.State"
},
{
"referenceName": "System.Tags",
"name": "Tags",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Tags"
}
],
"sortColumns": [
{
"field": {
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
"descending": false
},
{
"field": {
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
"descending": false
}
],
"workItemRelations": [
{
"rel": null,
"source": null,
"target": {
"id": 6,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/6"
}
},
{
"rel": "System.LinkTypes.Hierarchy-Forward",
"source": {
"id": 6,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/6"
},
"target": {
"id": 10,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/10"
}
},
...
因此,看起来好像没有返回我在WIQL中指定的列,我将不得不转过头来查询此查询返回的每个工作项ID的工作项api。我想避免进行20多个rest调用来解析所需的数据。有更好的方法吗?
谢谢
答案 0 :(得分:3)
您可以使用OData API查询工作项数据。 https://analytics.dev.azure.com/{OrganizationName}/{ProjectName}/_odata/{version}
对于以下Powershell脚本示例:
$ourl = "https://analytics.dev.azure.com/{AzureOrganizationName}/{ProjectName}/_odata/v3.0-preview/WorkItems?`$filter=Iteration/IterationPath eq 'iterationName\iteration 5' and WorkItemType ne 'Task'&`$expand=Children(`$filter=WorkItemType ne '')&`$select=WorkItemId, Title, State"
$full="Personal access token"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($full)"))
$result = Invoke-RestMethod -Uri $ourl -Method Get -Header @{Authorization = "Basic $base64AuthInfo"}
$result.value
您可以从下面的返回结果中看到,返回了所需的工作项列。
检查文档Query for linked work items中的示例以查询链接的工作项。
希望上面有帮助!