在 Azure DevOps 中,如何查询未完成并结转到当前 sprint 迭代的用户故事?
In Azure DevOps, how to query user stories that were not completed and are carried over to current sprint iteration?
我正在尝试使用比我目前所做的更好的方法列出未完成的用户故事并转移到当前 sprint。输出应该列出不是在当前 sprint 迭代中创建的用户故事,而且它必须至少在任何之前的迭代中被激活一次才能被列出。我的输出是正确的,但问题是我必须手动更改日期,因为我使用创建日期字段并手动将其设置为大于当前 sprint 迭代的开始日期。有没有另一种方法可以检测用户故事是否曾经出现在之前的 sprint 迭代中,以便我可以列出那些是否被转移到当前 sprint 的用户故事?我在考虑比较故事的创建日期,这样就不会列出新故事,但我没有找到正确的参数。
我觉得,你用的是最好的方法。您可以添加日期宏(如 @StartOfWeek-1),这有助于分析您的用户故事,而无需更改查询中的日期 (Start of Day, Week, Month, or Year date-based queries). Additionally, you can use the Power BI reporting where you can analyse each history revision of work items and find previous iterations. Connect to Analytics with Power BI Data Connector
我们无法通过内置工作项查询实现这一点,但我们可以通过在脚本中调用 REST API 来实现这一点 (Wiql - Query By Wiql and Revisions - Get)。
请尝试以下适用于我的 PowerShell 脚本:(您也可以将列表导出为 CSV 文件,然后使用 Microsoft Excel 打开)
它从特定团队的当前迭代中查询未完成的 User Story
,然后检索每个团队的工作项修订以检测 System.IterationPath
字段以获取所有值。如果该字段有多个唯一值,则意味着工作项从先前的迭代转移到当前的 sprint 迭代:
Param(
[string]$baseurl = "https://dev.azure.com/{organization}",
[string]$projectName = "project name",
[string]$user = "username",
[string]$token = "password/PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
# Query the work items with wiql
$uri = "$baseurl/$($projectName)/_apis/wit/wiql?api-version=5.1"
function CreateJsonBody
{
$value = @"
{
"query": "Select [System.Id], [System.Title], [System.State],[System.Tags] From WorkItems Where [System.WorkItemType] = 'User Story' AND [System.State] <> 'Closed' AND [System.State] <> 'Removed' AND [System.IterationPath] = @currentIteration('[Agile-0219]\Agile-0219 Team') order by [System.CreatedDate] desc"
}
"@
return $value
}
$json = CreateJsonBody
#Get the urls for WIs
$queryresult = Invoke-RestMethod -Uri $uri -Method POST -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$wiurls = $queryresult.workItems.url
#Filter the work items which carried from other iterations to current iteration
$wis = @()
cls
foreach($wiurl in $wiurls){
#Set the work item revision URL
$revurl = "$wiurl/revisions"
$wi = (Invoke-RestMethod -Uri $revurl -Method GET -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
#Detect the Unique iterations which the work item ever been involved
$iterationcount = ($wi.value.fields.'System.IterationPath'|select -Unique).count
#write-host $iterationcount
if ($iterationcount -gt 1) # Filter the work items which moved from other iterations
{
# Select the latest revision
$wilatest = ($wi.value | Select -last 1)
$customObject = new-object PSObject -property @{
"WitID" = $wilatest.id
"Title" = $wilatest.fields.'System.Title'
"AssignedTo" = $wilatest.fields.'System.AssignedTo'.displayName
"ChangedDate" = $wilatest.fields.'System.ChangedDate'
"ChangedBy" = $wilatest.fields.'System.ChangedBy'.displayName
"WorkItemType" = $wilatest.fields.'System.WorkItemType'
"State" = $wilatest.fields.'System.State'
"URL" = $wilatest.url
}
$wis += $customObject
}
}
$wis | Select-Object `
WitID,
Title,
AssignedTo,
ChangedDate,
ChangedBy,
WorkItemType,
State,
URL #|export-csv -Path D:\sample.csv -NoTypeInformation
更新
如果你想在查询中按创建日期过滤,那么你只需要添加过滤条件,如:AND [System.CreatedDate] < '2019-10-10'
所以,查询应该是:
"Select [System.Id], [System.Title], [System.State],[System.Tags] From WorkItems Where [System.WorkItemType] = 'User Story' AND [System.State] <> 'Closed' AND [System.State] <> 'Removed' AND [System.IterationPath] = @currentIteration AND [System.CreatedDate] < '2019-10-10' order by [System.CreatedDate] desc"
我正在尝试使用比我目前所做的更好的方法列出未完成的用户故事并转移到当前 sprint。输出应该列出不是在当前 sprint 迭代中创建的用户故事,而且它必须至少在任何之前的迭代中被激活一次才能被列出。我的输出是正确的,但问题是我必须手动更改日期,因为我使用创建日期字段并手动将其设置为大于当前 sprint 迭代的开始日期。有没有另一种方法可以检测用户故事是否曾经出现在之前的 sprint 迭代中,以便我可以列出那些是否被转移到当前 sprint 的用户故事?我在考虑比较故事的创建日期,这样就不会列出新故事,但我没有找到正确的参数。
我觉得,你用的是最好的方法。您可以添加日期宏(如 @StartOfWeek-1),这有助于分析您的用户故事,而无需更改查询中的日期 (Start of Day, Week, Month, or Year date-based queries). Additionally, you can use the Power BI reporting where you can analyse each history revision of work items and find previous iterations. Connect to Analytics with Power BI Data Connector
我们无法通过内置工作项查询实现这一点,但我们可以通过在脚本中调用 REST API 来实现这一点 (Wiql - Query By Wiql and Revisions - Get)。
请尝试以下适用于我的 PowerShell 脚本:(您也可以将列表导出为 CSV 文件,然后使用 Microsoft Excel 打开)
它从特定团队的当前迭代中查询未完成的 User Story
,然后检索每个团队的工作项修订以检测 System.IterationPath
字段以获取所有值。如果该字段有多个唯一值,则意味着工作项从先前的迭代转移到当前的 sprint 迭代:
Param(
[string]$baseurl = "https://dev.azure.com/{organization}",
[string]$projectName = "project name",
[string]$user = "username",
[string]$token = "password/PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
# Query the work items with wiql
$uri = "$baseurl/$($projectName)/_apis/wit/wiql?api-version=5.1"
function CreateJsonBody
{
$value = @"
{
"query": "Select [System.Id], [System.Title], [System.State],[System.Tags] From WorkItems Where [System.WorkItemType] = 'User Story' AND [System.State] <> 'Closed' AND [System.State] <> 'Removed' AND [System.IterationPath] = @currentIteration('[Agile-0219]\Agile-0219 Team') order by [System.CreatedDate] desc"
}
"@
return $value
}
$json = CreateJsonBody
#Get the urls for WIs
$queryresult = Invoke-RestMethod -Uri $uri -Method POST -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$wiurls = $queryresult.workItems.url
#Filter the work items which carried from other iterations to current iteration
$wis = @()
cls
foreach($wiurl in $wiurls){
#Set the work item revision URL
$revurl = "$wiurl/revisions"
$wi = (Invoke-RestMethod -Uri $revurl -Method GET -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
#Detect the Unique iterations which the work item ever been involved
$iterationcount = ($wi.value.fields.'System.IterationPath'|select -Unique).count
#write-host $iterationcount
if ($iterationcount -gt 1) # Filter the work items which moved from other iterations
{
# Select the latest revision
$wilatest = ($wi.value | Select -last 1)
$customObject = new-object PSObject -property @{
"WitID" = $wilatest.id
"Title" = $wilatest.fields.'System.Title'
"AssignedTo" = $wilatest.fields.'System.AssignedTo'.displayName
"ChangedDate" = $wilatest.fields.'System.ChangedDate'
"ChangedBy" = $wilatest.fields.'System.ChangedBy'.displayName
"WorkItemType" = $wilatest.fields.'System.WorkItemType'
"State" = $wilatest.fields.'System.State'
"URL" = $wilatest.url
}
$wis += $customObject
}
}
$wis | Select-Object `
WitID,
Title,
AssignedTo,
ChangedDate,
ChangedBy,
WorkItemType,
State,
URL #|export-csv -Path D:\sample.csv -NoTypeInformation
更新
如果你想在查询中按创建日期过滤,那么你只需要添加过滤条件,如:AND [System.CreatedDate] < '2019-10-10'
所以,查询应该是:
"Select [System.Id], [System.Title], [System.State],[System.Tags] From WorkItems Where [System.WorkItemType] = 'User Story' AND [System.State] <> 'Closed' AND [System.State] <> 'Removed' AND [System.IterationPath] = @currentIteration AND [System.CreatedDate] < '2019-10-10' order by [System.CreatedDate] desc"