Skip to content

Template Variables

Step run lines and env values in command specs are rendered as Go templates before execution. This lets you inject arguments, environment variables, and system info into your commands.

VariableDescription
{{.args.X}}Argument value (positional or flag) by name
{{.env.X}}Environment variable value
{{.cwd}}Current working directory
{{.home}}User’s home directory
args:
positional:
- name: environment
required: true
flags:
- name: replicas
type: int
default: "3"
steps:
- name: deploy
run:
- echo "Deploying to {{.args.environment}} with {{.args.replicas}} replicas"

Running my cli run deploy -- production --replicas 5 renders the command as:

Deploying to production with 5 replicas

Reference both default env vars and system environment variables:

defaults:
env:
GREETING: Hello
steps:
- name: greet
run:
- echo "{{.env.GREETING}} from {{.env.USER}}"
steps:
- name: info
run:
- echo "Running from {{.cwd}}"
- echo "Home is {{.home}}"
- cat {{.home}}/.config/app.yaml

Since these are Go templates, you can use standard Go template functions:

steps:
- name: example
run:
# Conditionals
- '{{if .args.verbose}}set -x{{end}}'
# Default values
- echo "Region: {{or .args.region "us-east-1"}}"

You can also use templates in step-level env values:

steps:
- name: build
env:
DEPLOY_TARGET: "{{.args.environment}}"
CONFIG_PATH: "{{.home}}/.config/deploy.yaml"
run:
- ./build.sh