首页 > 解决方案 > 在 TFS 2015 中,对于失败的 VNext 构建,构建失败的步骤(构建任务)是否存储在 DB 中的任何位置

问题描述

我知道如果我单击构建链接以获取摘要,它会显示所有步骤,但我无法使用 API 或查看 TFS 数据库在任何地方找到构建失败的实际步骤(构建任务)。

TFS 2015 是否将其存储在任何可访问的地方?

标签: tfstfs-2015vnext

解决方案


Timeline您可以使用 REST API ( Timeline - Get )从构建中检索失败的步骤

只需尝试以下 PowerShell 示例以从构建中检索失败的步骤(构建任务):

Param(
   [string]$collectionurl = "http://ictfs2015:8080/tfs/DefaultCollection",
   [string]$projectName = "ProjectName",
   [string]$BuildId = "44",
   [string]$user = "username",
   [string]$token = "password"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$uri = "$($collectionurl)/$($projectName)/_apis/build/builds/$BuildId/timeline?api-version=2.0"
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$steps = $response.records | where {$_.result -eq 'failed' -and $_.type -eq 'Task'} # Filter the failed steps

$failedsteps = @()

foreach($step in $steps){

    $customObject = new-object PSObject -property @{
          "StepId" = $step.id
          "type" = $step.type
          "TaskName" = $step.name
          "startTime" = $step.startTime
          "finishTime" = $step.finishTime
          "state" = $step.state
          "result" = $step.result
          "changeId" = $step.changeId
          "workerName" = $step.workerName
        } 

    $failedsteps += $customObject       
}

$failedsteps | Select `
                StepId, 
                type, 
                TaskName,
                startTime,
                finishTime,
                state,
                result,
                changeId,
                workerName #|export-csv -Path C:\FailedBuildSteps.csv -NoTypeInformation

在此处输入图像描述


推荐阅读