Webhook icon
Schedule icon
WorkingDirectory icon
Commands icon
Docker icon
Script icon
If icon
SlackIncomingWebhook icon
Fail icon
Log icon

Catch TeamCity Queue Stalls Before Builds Time Out

Score TeamCity build queue snapshots against a configurable SLA, alert Slack when builds stall in the queue, and gate the pipeline in Kestra.

Categories
Infrastructure

How it works

  1. on_queue_snapshot (io.kestra.plugin.core.trigger.Webhook, keyed with the TEAMCITY_QUEUE_WEBHOOK_KEY secret) receives the build queue snapshot from your TeamCity observer right after it polls the server. hourly_queue_sweep (io.kestra.plugin.core.trigger.Schedule, cron 0 * * * *) is the safety net and ships disabled: true until an operator turns it on.
  2. queue_workspace (io.kestra.plugin.core.flow.WorkingDirectory) opens one shared directory so the staged snapshot and the scorer read the same file.
  3. stage_queue_snapshot (io.kestra.plugin.scripts.shell.Commands on the io.kestra.plugin.scripts.runner.docker.Docker runner, image alpine:3.20) writes teamcity_queue.json with a heredoc holding three queued builds where one has waited 47 minutes, plus a running build that must not count toward the stall verdict.
  4. score_queue (io.kestra.plugin.scripts.python.Script on python:3.12-slim) prefers the posted webhook body and falls back to the staged snapshot, keeps only builds in the queued state, clamps negative waits to zero, and flags every build whose wait reached queue_sla_minutes. The verdict, the stall count, the oldest wait and the stalled rows are printed as a single ::{"outputs": ...}:: line.
  5. stall_gate (io.kestra.plugin.core.flow.If) branches on queue_ok and stalled_count > 0. A stall reaches alert_stall (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) with the stalled build types, then enforce_gate (io.kestra.plugin.core.flow.If) applies the fail_on_stall policy with fail_execution (io.kestra.plugin.core.execution.Fail) or the report only log_gate_softened. A healthy or unreadable queue lands on log_queue_healthy.
  6. The flow level errors handler (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) reports any failure with the execution id, because a gate that dies silently looks exactly like a healthy queue.

What you get

  • A per build stall verdict driven by one SLA input, so the gate adapts when your agents get faster or slower.
  • A Slack alert naming the stalled build types and the oldest wait, enough for the on call to free an agent without opening TeamCity first.
  • A fail versus report policy in one input, so the same flow gates the pipeline or feeds a weekly digest.
  • stalled_count, oldest_queued_minutes, queue_status, queued_count and stalled_builds as typed outputs for dashboards and ticket automation.
  • A disabled hourly sweep as a second net once the webhook path is trusted.

Who it's for

  • Build engineers responsible for TeamCity agents who need pending builds surfaced before release deadlines slip.
  • SREs on call who want a queue stall to page the same channel as every other pipeline failure.
  • Platform teams standardizing release gates across CI servers with a flow that reads the same way as the rest of the estate.

Why orchestrate this with Kestra

TeamCity reports its queue in its own UI, which nobody watches at 2 a.m., and a stalled build looks identical to a slow one until the artifact misses its window. Kestra gives the snapshot a webhook to land on, a shared workspace for the fixture and the scorer, a branch that separates a stall from a healthy queue, a policy input for fail versus report, and outputs a dashboard or ticket can consume. The SLA, the escalation policy and the execution history that proves the gate ran all live in one version controlled file.

Prerequisites

  • A worker with Docker access, the fixture runs in alpine:3.20 and the scorer in python:3.12-slim.
  • A TeamCity observer or polling job that can POST the build queue snapshot, or rely on the bundled fixture for trial runs.
  • A Slack incoming webhook for the stall alert and for failure alerts.

Secrets

  • TEAMCITY_QUEUE_WEBHOOK_KEY: key segment guarding the queue webhook URL, anyone holding it can trigger a gate run.
  • SLACK_WEBHOOK_URL: Slack incoming webhook for the stall alert and failure alerts.

Quick start

  1. Add the two secrets to your Kestra namespace.
  2. Run the flow once with the default inputs and confirm queue_status reads STALLED, stalled_count reads 1, oldest_queued_minutes reads 47, and the Slack alert arrived.
  3. Raise queue_sla_minutes to 60 and re-run to watch the same snapshot pass as HEALTHY while the counters stay identical.
  4. Re-run with fail_on_stall set to false and watch log_gate_softened keep the execution green while the alert still fires.
  5. Point your observer at /api/v1/{tenant}/executions/webhook/{namespace}/teamcity-build-queue-stall-gate/{TEAMCITY_QUEUE_WEBHOOK_KEY} and enable hourly_queue_sweep once the path is trusted.

How to extend

  • Pull the live queue yourself with an io.kestra.plugin.core.http.Request against the TeamCity REST API before scoring, keeping the staged fixture as the offline fallback.
  • Persist every snapshot with io.kestra.plugin.jdbc.postgresql.Queries to chart queue wait percentiles over weeks.
  • Fan out per project with io.kestra.plugin.core.flow.Loop over a subflow that gates one project queue each.
  • File a ticket automatically with io.kestra.plugin.github.issues.Create when a stall repeats across consecutive runs.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.