Trigger a TeamCity build for the current branch
Triggers a TeamCity build for the current branch with configurable build type.
/plugin marketplace add postsharp/PostSharp.Engineering.AISkills/plugin install eng@postsharp-engineering[BuildType]Trigger a build on TeamCity for the current branch.
$ARGUMENTS - Optional build type (default: DebugBuild). Common types: DebugBuild, ReleaseBuild
.teamcity/settings.kts to find:
object <Name> : BuildTypeAbsoluteId("...") in vcs block - extract project prefixgit rev-parse --abbrev-ref HEAD<ProjectPrefix>_<BuildTypeName> (e.g., if VCS root is Metalama_Metalama20260_Metalama, build type ID is 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 callsTEAMCITY_CLOUD_TOKEN on the hostWhen running on host (RUNNING_IN_DOCKER not set or false):
TEAMCITY_CLOUD_TOKEN environment variable for authenticationInvoke-RestMethod for API callsConstruct Request Body:
$body = @{
buildType = @{id = $buildTypeId}
branchName = $branchName
} | ConvertTo-Json -Compress
Trigger Build:
$result = Invoke-RestMethod `
-Uri 'https://postsharp.teamcity.com/app/rest/buildQueue' `
-Method Post `
-Headers @{
Authorization = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
Accept = 'application/json'
} `
-ContentType 'application/json' `
-Body $body
Extract and display build information from the response:
Write-Host "Build queued successfully!" -ForegroundColor Green
Write-Host ""
Write-Host "Build #$($result.id) - $($result.buildType.name)" -ForegroundColor Cyan
Write-Host "Branch: $($result.branchName)"
Write-Host "Status: $($result.state)" -ForegroundColor Yellow
Write-Host ""
Write-Host "Build URL: $($result.webUrl)" -ForegroundColor Cyan
Key Response Fields:
| Field | Description | Example |
|---|---|---|
id | Build ID | 12345 |
buildType.id | Build type ID | Metalama_DebugBuild |
buildType.name | Build configuration name | "Build [Debug]" |
branchName | Git branch | topic/2026.0/1234-fix |
state | Build state | queued |
webUrl | Link to build in TC UI | Full URL |
queuedDate | When build was queued | ISO 8601 timestamp |
Docker Environment:
mcp__host-approval__ExecuteCommand tool for PowerShell commandsHost Environment:
TEAMCITY_CLOUD_TOKEN is set in environmentAuthentication Errors:
TEAMCITY_CLOUD_TOKEN not set, display error messageRUNNING_IN_DOCKER environment variable to provide appropriate error contextAPI Errors:
Common Issues:
# 1. Get current branch
$branch = git rev-parse --abbrev-ref HEAD
# 2. Construct build type ID (example)
$buildTypeId = "Metalama_Metalama20260_Metalama_DebugBuild"
# 3. Build request body
$body = @{
buildType = @{id = $buildTypeId}
branchName = $branch
} | ConvertTo-Json -Compress
# 4. Trigger build
try {
$result = Invoke-RestMethod `
-Uri 'https://postsharp.teamcity.com/app/rest/buildQueue' `
-Method Post `
-Headers @{
Authorization = "Bearer $env:TEAMCITY_CLOUD_TOKEN"
Accept = 'application/json'
} `
-ContentType 'application/json' `
-Body $body
# 5. Display success
Write-Host "Build queued successfully!" -ForegroundColor Green
Write-Host "Build #$($result.id) - $($result.buildType.name)"
Write-Host "URL: $($result.webUrl)" -ForegroundColor Cyan
}
catch {
Write-Host "Error triggering build: $($_.Exception.Message)" -ForegroundColor Red
}