Scripting and Automation
TeamCity CLI provides several output formats and features designed for scripting, automation, and CI/CD integration.
JSON output
Many commands support a --json flag for machine-readable output. List commands also accept optional field selection.
Basic usage
Discovering available fields
Pass --json= (with an empty value) to see all available fields for a command:

Selecting specific fields
Specify a comma-separated list of fields:
Field selection (--json=...) is available on list commands only. View and inspection commands accept --json without field selection.
Nested fields
Use dot notation to access nested fields:
JSON for view and inspection commands
Available fields by command
Command | Example fields |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Plain text output
Use --plain for tab-separated output that is easy to parse with standard Unix tools:
Omit the header row for cleaner piping:
Scripting examples
Get IDs of failed builds
Export build data to CSV
Get web URLs for queued builds
Count builds by status
Wait for a build to finish
Cancel all queued builds for a job
CI/CD integration
Environment variable authentication
In CI/CD pipelines, use environment variables for authentication:
PowerShell:
CMD:
See Authentication for details.
Non-interactive mode
Use --no-input to disable interactive prompts in automated environments. The CLI uses sensible defaults when prompts are suppressed:
Alternatively, use --force on commands that support it:
Read-only mode
Set TEAMCITY_RO=1 to prevent any write operations. In this mode, commands that would modify data (triggering builds, canceling, pinning, changing parameters, and so on) are rejected before a request is sent:
This is useful for monitoring dashboards, reporting scripts, and shared environments where accidental modifications must be prevented. The flag also blocks write operations through teamcity api with non-GET methods.
See Configuration for accepted values.
Quiet mode
Use --quiet to suppress non-essential output:
Exit codes
Most commands return exit code 0 on success and 1 on failure. The teamcity run watch flow (including teamcity run start --watch) returns:
2when a run is canceled124on timeout
Raw API access
For operations not covered by dedicated commands, use teamcity api to make direct REST API requests:
See REST API access for details.