Skip to content

exec

Source: builtin/exec

Shell command execution.

Provider configuration

NameTypeRequiredDefaultDescription
dirstringno—Default working directory for commands. Relative paths are resolved against the process cwd.
envmap(string)no—Default environment variables merged into every action’s env.
inherit_envboolnotrueStart each command’s environment from orchard’s own. Set false to pass only env.

Actions

exec_run

Run a program and capture stdout/stderr/exit_code.

Non-zero exit is an error by default — the action fails and downstream actions don’t run.

Run a program with explicit arguments.

action "exec_run" "migrate" {
  command = "psql"
  args    = ["-f", "migrations/001.sql"]
}

Attributes

NameTypeRequiredDefaultDescription
argslist(string)no—Arguments passed after the command.
commandstringyes—Program to run. Absolute path or resolved via PATH.
dirstringno—Override the provider’s default working directory for this action.
envmap(string)no—Per-action environment variables. Merged over provider defaults; per-action wins on conflicts.
stdinstringno—Data written to the process’s stdin. Omit for no stdin.

Outputs

Type: object({exit_code=number,stderr=string,stdout=string}).

Captured output streams and exit code. Only produced on successful (exit 0) completion; non-zero exit fails the action and surfaces the first 400 bytes of stderr in the error message.

FieldTypeDescription
stdoutstringCaptured stdout.
stderrstringCaptured stderr.
exit_codenumberProcess exit code (always 0 when outputs are produced).

Examples

Build an artefact and capture its SHA256.

scenario "build_and_upload" {
  required_providers {
    exec = { source = "builtin/exec" }
  }

  provider "exec" {
    dir = "."
    env = {
      CI = "true"
    }
  }

  action "exec_run" "build" {
    command = "go"
    args    = ["build", "-o", "bin/app", "./cmd/app"]
  }

  action "exec_run" "hash" {
    depends_on = [action.exec_run.build]
    command    = "shasum"
    args       = ["-a", "256", "bin/app"]
  }

  output "checksum" { value = action.exec_run.hash.stdout }
}

Notes

  • Environment construction. The child process’s environment is built by starting from os.Environ(), layering the provider’s env, then the action’s env. Later layers win on conflicts. With inherit_env = false it starts empty instead, so a run doesn’t depend on the host’s environment; command is still looked up on orchard’s own PATH, but pass PATH in env if the program runs others by name.

  • Working directory. Per-action dir overrides the provider default. If neither is set, the child inherits the parent’s cwd.

  • Shell expansion. command and args are passed directly to exec.Command — no shell is invoked, no glob expansion, no variable expansion. If you need a shell, run sh -c "..." explicitly:

    action "exec_run" "pipeline" {
      command = "sh"
      args    = ["-c", "ls | wc -l"]
    }
  • Timeouts. Use the action-level timeout attribute to bound execution:

    action "exec_run" "long_job" {
      timeout = "5m"
      command = "./slow-script.sh"
    }