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?
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