WEBINARLive webinar: Terraform in Buddy, Oct 21st.Terraform: plan, approve, apply with state in Buddy. Live on October 21st.Save your seat

bdy target exec command

View as Markdown
$bdy target exec command|cmd [options] <identifier> [command]

Execute a command on a target Required scopes: TARGET_USE

ARGUMENTS
identifier
Target identifier (required)
command
Command to execute on the target (e.g. a SQL query or a shell command) (required)
OPTIONS
--context <name>
Connection and scope context: default, git, link or a saved name. Overrides the globally active context for this invocation.
--examples
Show only examples; with this flag --format accepts text, json or jsonl
--verbose
Show REST API requests, responses, timing and retries on stderr
-w, --workspace <domain>
Workspace URL handle. Can be set via variable: BUDDY_WORKSPACE
-p, --project <name>
Project name. Can be set via variable: BUDDY_PROJECT
--pipeline <identifier>
Pipeline identifier to scope the target to. Requires --project
--environment <identifier>
Environment identifier to scope the target to. Resolves a workspace environment; add --project to point at a project environment
--async
Start the command and return the execution id without waiting for completion
--file <path>
Read the command from a file instead of the argument
--format <text|json>
Output format: json, text. JSON CLI errors: {error:{code,message,hint}}, exit 1 (2 or 3 with
--exit-code
Use semantic exit codes: 0 success, 1 unsuccessful, 2 command error, 3 not found, 8 pending
-h, --help
display help for command

Documentation for bdy v1.25.20

Last modified on Oct 14, 2026

Examples

Return the execution state using semantic exit codes
bdy target exec command target-identifier "SELECT 1" --exit-code$
Run a command on a target and print its output
bdy tg exec command target-identifier "ls -la"$
Run SQL on a MySQL target
bdy tg exec command target-identifier "SELECT 1"$
Start a command in background and return the execution id
bdy tg exec command target-identifier "ls -la" --async$
Run a command from a file
bdy tg exec command target-identifier --file ./query.sql$
Print the result with execution metadata as JSON
bdy tg exec command target-identifier "SELECT 1" --format json$