【发布时间】:2021-06-12 15:12:57
【问题描述】:
我需要动态拉取当前迭代和过去 n 个具有特定字段的工作项迭代。
向您详细解释过去 n 次迭代。 假设我的 n 为 5,那么我需要当前迭代、过去迭代到当前迭代以及过去到过去到当前迭代的工作项。
我总共有超过 400 次迭代,我需要从中提取最近 5 次迭代的工作项。
要从当前迭代中获取具有特定字段的工作项,这是我编写的 powershell 脚本
$token = 'your PAT'
$url="https://dev.azure.com/Organizationname/_apis/wit/wiql?api-version=5.1"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = @'
{
"query": "SELECT [System.Id], [System.WorkItemType], [System.State],[System.AreaPath],[System.Tags],[System.CommentCount],[System.ChangedDate]
FROM workitems
Where [System.AreaPath] = 'area path'
and [System.IterationPath] = 'iteration path'
and [System.WorkItemType] = 'Story'
order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}
'@
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json
$listOfTasks = New-Object Collections.Generic.List[String]
ForEach( $workitem in $response.workItems ) {
$listOfTasks.Add($workitem.id)
}
$listOfTasks = $listOfTasks -join ','
$listOfTasks
$JSON1 = @"
{
"ids": [$listOfTasks],
"fields": [
"System.Id",
"System.Title",
"System.WorkItemType",
"System.IterationPath",
]
}
"@
$JSON1
$url1="https://dev.azure.com/Organizationname/_apis/wit/workitemsbatch?api-version=5.0"
$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON1 -ContentType application/json
Write-Host "result = $($response1 | ConvertTo-Json -Depth 100)"
有人可以帮我调整这个逻辑,这样我就可以获得当前和过去的 n 次迭代工作项。 非常感谢提前!
【问题讨论】:
标签: azure-devops azure-devops-rest-api tfs-workitem wiql