Check the status of a TeamCity build
Retrieves and displays TeamCity build status, test results, and problem details.
/plugin marketplace add postsharp/PostSharp.Engineering.AISkills/plugin install eng@postsharp-engineering<buildId> [continuous]Check the status of a TeamCity build and display results.
$ARGUMENTS - Build ID or "latest" to check the most recent build for current branch (default: latest)
If argument is a build ID (numeric), use it directly. Otherwise:
git rev-parse --abbrev-ref HEAD.teamcity/settings.kts to find:
AbsoluteId("...") in vcs blockMetalama_Metalama20260_Metalama)<Prefix>_DebugBuild (e.g., Metalama_Metalama20260_Metalama_DebugBuild)Check RUNNING_IN_DOCKER environment variable to determine authentication method:
When running in Docker (RUNNING_IN_DOCKER=true):
Invoke-RestMethod for API callsWhen running on host (RUNNING_IN_DOCKER not set or false):
TEAMCITY_CLOUD_TOKEN environment variable for authenticationInvoke-RestMethod for API callsGet Specific Build by ID:
$build = Invoke-RestMethod -Method GET `
-Uri "https://postsharp.teamcity.com/app/rest/builds/id:$buildId" `
-Headers @{
"Authorization" = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
"Accept" = "application/json"
}
Get Latest Build for Branch/BuildType:
$builds = Invoke-RestMethod -Method GET `
-Uri "https://postsharp.teamcity.com/app/rest/builds?locator=buildType:$buildTypeId,branch:$branchName,count:1" `
-Headers @{
"Authorization" = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
"Accept" = "application/json"
}
$build = $builds.build[0]
Key Fields in Response:
| Field | Description | Values |
|---|---|---|
id | Build ID | Numeric |
status | Build result | SUCCESS, FAILURE, ERROR |
state | Build state | queued, running, finished |
statusText | Detailed status message | Text description of error/success |
webUrl | Link to build in TC UI | URL |
branchName | Git branch | Branch name |
startDate | When build started | ISO 8601 timestamp |
finishDate | When build finished | ISO 8601 timestamp (null if running) |
queuedDate | When build was queued | ISO 8601 timestamp |
buildType.name | Build configuration name | e.g., "Build [Debug]" |
agent.name | Build agent | Agent name |
problemOccurrences.count | Number of problems | Numeric |
Format output as:
Build #<number> (<buildType.name>)
Status: <status> (<state>)
Branch: <branchName>
<statusText>
Started: <startDate>
Finished: <finishDate> (or "Still running" if state=running)
Duration: <calculated from dates>
Agent: <agent.name>
Problems: <problemOccurrences.count>
URL: <webUrl>
If state == "running":
startDate--wait flagfinishDate == null to detect running stateIf problemOccurrences.count > 0, fetch details using PowerShell:
$problems = Invoke-RestMethod -Method GET `
-Uri "https://postsharp.teamcity.com/app/rest/problemOccurrences?locator=build:(id:$buildId)" `
-Headers @{
"Authorization" = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
"Accept" = "application/json"
}
Problem fields:
type: Problem type (e.g., TC_EXIT_CODE, TC_COMPILATION_ERROR, TC_FAILED_TESTS)identity: Step that faileddetails: Additional informationTest Summary in Build Response:
The build response includes a testOccurrences field with summary:
{
"count": 6553,
"failed": 2,
"passed": 6368,
"ignored": 183,
"href": "/app/rest/testOccurrences?locator=build:(id:311629)"
}
Get All Test Results:
$tests = Invoke-RestMethod -Method GET `
-Uri "https://postsharp.teamcity.com/app/rest/testOccurrences?locator=build:(id:$buildId)" `
-Headers @{
"Authorization" = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
"Accept" = "application/json"
}
Get Failed Tests Only:
$failedTests = Invoke-RestMethod -Method GET `
-Uri "https://postsharp.teamcity.com/app/rest/testOccurrences?locator=build:(id:$buildId),status:FAILURE" `
-Headers @{
"Authorization" = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
"Accept" = "application/json"
}
Get Detailed Test Information:
$testDetail = Invoke-RestMethod -Method GET `
-Uri "https://postsharp.teamcity.com/app/rest/testOccurrences/build:(id:$buildId),id:$testId" `
-Headers @{
"Authorization" = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
"Accept" = "application/json"
}
Test Occurrence Fields:
| Field | Description | Example |
|---|---|---|
id | Test occurrence ID | 2000007320 |
name | Full test name | TargetCode.Method() |
status | Test result | SUCCESS, FAILURE, UNKNOWN |
duration | Test duration in ms | 45 |
details | Full failure details including stack trace | Multi-line string with exception and stack |
test.name | Short test name | Method name only |
muted | Whether test is muted | true/false |
currentlyMuted | Whether currently muted | true/false |
href | Link to full test info | API URL |
Display Test Results:
When displaying failed tests:
testOccurrences in buildfailed > 0, fetch failed test detailsdetails field)# Get build info
$build = Invoke-RestMethod -Method GET `
-Uri "https://postsharp.teamcity.com/app/rest/builds/id:$buildId" `
-Headers @{
"Authorization" = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
"Accept" = "application/json"
}
# Display status
Write-Host "Build #$($build.number) - $($build.buildType.name)" -ForegroundColor Cyan
Write-Host "Status: $($build.status) ($($build.state))" -ForegroundColor $(
if ($build.status -eq "SUCCESS") { "Green" } else { "Red" }
)
Write-Host "Branch: $($build.branchName)"
Write-Host $build.statusText
Write-Host ""
Write-Host "Started: $($build.startDate)"
if ($build.state -eq "finished") {
Write-Host "Finished: $($build.finishDate)"
$duration = [DateTime]::Parse($build.finishDate) - [DateTime]::Parse($build.startDate)
Write-Host "Duration: $($duration.ToString('hh\:mm\:ss'))"
} else {
Write-Host "Still running..."
$elapsed = [DateTime]::UtcNow - [DateTime]::Parse($build.startDate)
Write-Host "Elapsed: $($elapsed.ToString('hh\:mm\:ss'))"
}
Write-Host ""
Write-Host "Agent: $($build.agent.name)"
if ($build.problemOccurrences.count -gt 0) {
Write-Host "Problems: $($build.problemOccurrences.count)" -ForegroundColor Yellow
}
# Display test results summary
if ($build.testOccurrences) {
Write-Host ""
Write-Host "Tests: $($build.testOccurrences.count) total, " -NoNewline
Write-Host "$($build.testOccurrences.passed) passed, " -NoNewline -ForegroundColor Green
if ($build.testOccurrences.failed -gt 0) {
Write-Host "$($build.testOccurrences.failed) failed, " -NoNewline -ForegroundColor Red
}
Write-Host "$($build.testOccurrences.ignored) ignored" -ForegroundColor Gray
# Show failed tests if any
if ($build.testOccurrences.failed -gt 0) {
Write-Host ""
Write-Host "Failed Tests:" -ForegroundColor Red
$failedTests = Invoke-RestMethod -Method GET `
-Uri "https://postsharp.teamcity.com/app/rest/testOccurrences?locator=build:(id:$buildId),status:FAILURE" `
-Headers @{
"Authorization" = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
"Accept" = "application/json"
}
foreach ($test in $failedTests.testOccurrence) {
Write-Host " - $($test.name)" -ForegroundColor Yellow
if ($test.details) {
# Show first line of error
$errorLine = ($test.details -split "`n")[0]
Write-Host " $errorLine" -ForegroundColor DarkGray
}
}
}
}
Write-Host ""
Write-Host "URL: $($build.webUrl)" -ForegroundColor Cyan
Base URL: https://postsharp.teamcity.com/app/rest
Authentication: Bearer token via TEAMCITY_CLOUD_TOKEN environment variable
Common Locators:
id:<buildId>buildType:<buildTypeId>,count:1buildType:<buildTypeId>,branch:<branchName>,count:1buildType:<buildTypeId>,running:truebuildType:<buildTypeId>,status:FAILURE,count:10Useful Endpoints:
/app/rest/builds/id:<id> - Get specific build/app/rest/builds?locator=... - Query builds/app/rest/problemOccurrences?locator=build:(id:<id>) - Get problems/app/rest/testOccurrences?locator=build:(id:<id>) - Get test results/app/rest/builds/id:<id>/statistics - Get build statisticsAuthentication Errors:
TEAMCITY_CLOUD_TOKEN not set, display error messageRUNNING_IN_DOCKER environment variable to provide appropriate error contextAPI Errors: