Azure DevOps - 工作项在看板上特定列中花费的时间

标签 azure azure-devops odata devops

我想报告一下功能在我们看板的每一列中花费的天数。

因此,对于我想要的示例输出,我们有一个带有列的看板:

Funnel           --> Workitem X spend 10 days in here
Analyzing        --> Workitem X spend 13 days in here
Backlog          --> Workitem X spend  3 days in here
Implementing     --> Workitem X spend 11 days in here
Done             --> Workitem X spend 50 days in here

到目前为止我尝试过

  • 分析 View :没有可以添加到输出字段的 BoardColumn
  • OData:找到了一种根据当前 WorkItem 状态获取列值 (BoardLocation) 的方法
  • OData:WorkItemSnapshot(用于获取历史数据)不支持 BoardLocation。

你们知道我可以检索有关功能及其 BoardColumns 的历史数据的任何方法吗?

提前致谢, 乔斯特

最佳答案

我们可以使用 Rest API 和 power shell 来做到这一点。

  1. 通过 Wiql query 按状态获取所有工作项 ID .

示例脚本:

$connectionToken="pat"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$WorkItemQueryURL = "https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=6.0" 

$body =@"
{
  "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'User Story' AND [State] = 'Closed' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}
"@
$WorkItem = Invoke-RestMethod -Uri $WorkItemQueryURL -ContentType "application/json" -Body $body -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST

Write-host $WorkItem.workItems.id

结果:

enter image description here

  • 我们可以通过 REST API 获取字段 Microsoft.VSTS.Common.StateChangeDate 的值 Get Work Item ,就是状态发生变化的时间,那么我们就可以计算出从状态变为xxx以来,已经在这个状态度过了多少天了。
  • 示例脚本:

    Write-host $WorkItem.workItems.id
    
    ForEach ($ID in $WorkItem.workItems.id)
    {
       $WorkItemInfoURL = "https://dev.azure.com/v-viliu/test/_apis/wit/workitems/$($ID)?api-version=6.0" 
    
       $WorkItemDetail = (Invoke-RestMethod -Uri $WorkItemInfoURL -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
       
       $StateChangeDate = $WorkItemDetail.fields."Microsoft.VSTS.Common.StateChangeDate"
    
       Write-host "Work item ID: $ID and StateChangeDate is $StateChangeDate"
    
    }
    

    结果:

    enter image description here

  • 计算自状态更改为 xxx 以来已处于该状态的天数。
  • 示例脚本:

    $current = Get-Date
    
    $SpendDate= New-TimeSpan -Start $current -End $StateChangeDate 
    
    Write-Output "The spend date is: $SpendDate"
    

    注意:需要更改当前日期格式,可以引用这个doc了解更多详情。

    关于Azure DevOps - 工作项在看板上特定列中花费的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64262879/

    相关文章:

    azure - 没有选择更改为手动 SCIM 配置

    azure - SQL Azure 故障转移

    azure - 从 Azure PowerShell 任务调用 PowerShell 函数时未获得预期输出

    sql - SEDE 的 DAYOFWEEK 函数?

    search - OData V6.6.0 不允许 $search

    odata - OData 代理的编程生成

    Azure Powershell - 根据私有(private)IP查找NIC

    azure - 授予服务主体访问 ADLS 文件的正确方法

    c# - 通过 Azure DevOps Services Rest Api 完成的 Pull 请求的列表

    azure - 通过 Visual Studio Online 执行 Azure 云服务 CI 构建时如何构建单元测试项目?