0

I know if I click on a build link for a summary, it shows all the steps, but I cannot find the actual step (build task) that the build failed on anywhere using the API or looking in the TFS database.

Does TFS 2015 store this anywhere that is accessible?

Thaldin
  • 283
  • 3
  • 15
  • It stores it in the build results. What problem are you trying to solve? – Daniel Mann Jun 05 '18 at 19:24
  • I am trying to do some statistics on build definition failures to see which build tasks historically have the most failures. – Thaldin Jun 05 '18 at 21:49
  • @DanielMann - I have looked for a build results table, but I can't seem to find it. I have checked in the Warehouse and the DefaultCollection database. Am I just missing it, or it is somewhere else? – Thaldin Jun 05 '18 at 22:02

1 Answers1

1

You can retrieve the failed steps from build Timeline with the REST API (Timeline - Get)

Just try below PowerShell sample to retrieve the failed steps (build task) from a build:

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

enter image description here

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • Thank you! This is exactly what I have been looking for. I have been manually iterating through the logs and it's painful. – Thaldin Jun 06 '18 at 20:09