Variables Reference
Workflow fields read values through ${...} references such as ${params.region} or ${steps.build.outputs.image}. This page owns the reference forms, when each resolves, and which value wins when two sources define the same name.
Run metadata such as ${context.run.id} is listed in Runtime Variables. How YAML, Dagu, and the shell each treat quotes is in Quoting and Escaping.
When Values Resolve
Dagu does not render the whole file up front. Each field resolves when it is about to be used, so a reference can only read values that exist at that moment.
- Load:
constsresolve while the DAG file is read. They can only reference earlierconsts. - Run start: parameters,
evaldefaults, dates, the runtime profile, secrets, rootenv, and dotenv files resolve before any step runs. - Step start: step fields resolve right before the step runs, so they can read outputs of steps that already finished.
- Inside the process: in
run, unqualified$NAME,${NAME},$(...), and backticks are left for the shell.
Only params[].eval and precondition eval run $(...) or backtick commands inside Dagu. Everywhere else that text passes through unchanged.
Reference Forms
| Form | Reads | Resolves | Details |
|---|---|---|---|
${consts.name} | An immutable value from root consts | Load | Constants |
${params.name} | A named parameter | Run start | Parameters |
${params} | All resolved parameters as one JSON string, same as DAG_PARAMS_JSON | Run start | Parameter Payload |
${env.NAME} | A value from the current environment scope | Run start or step start | Environment Variables |
${dates.NAME} | A date derived from the run's schedule slot | Run start | Schedule Dates |
${context.run.id} | Run, attempt, step, trigger, path, profile, or push-back metadata | Run start or step start | Runtime Variables |
${steps.ID.outputs.NAME} | A declared output of a finished step | Step start | Outputs |
${foreach.item}, ${foreach.index}, ${foreach.key} | The current item in a foreach body | Step start | Foreach |
${inputs.NAME}, ${outputs.NAME} | Input and staging paths in a type: build step | Step start | Build Workflows |
${node.name} | The node a bound run runs on | Run start | Node Targeting |
$NAME, ${NAME} | Unqualified environment syntax | Depends on the field | Unqualified Variables |
Namespace and name rules: names match ^[A-Za-z][A-Za-z0-9_]*$, and environment names match ^[A-Za-z_][A-Za-z0-9_]*$. Only the braced forms above are references. $params.name without braces is ordinary text.
consts:
- registry: registry.example.com
params:
- name: environment
default: staging
steps:
- id: build
run: |
printf 'image=%s/api:%s\n' "${consts.registry}" "${context.run.id}" >> "$DAGU_OUTPUT_FILE"
outputs:
- name: image
- id: deploy
run: ./deploy.sh --env "${params.environment}" --image "${steps.build.outputs.image}"deploy reads build's output, so Dagu runs build first even without depends. See Dependencies.
Constants
consts holds values fixed when the workflow is written. Entries are a list of single-key maps with a string, number, or boolean value, and each entry can reference only earlier entries.
consts:
- service: api
- image_repo: registry.example.com/${consts.service}
steps:
- id: print_repo
run: echo "${consts.image_repo}"consts cannot read params, env, or step outputs, because none of them exist at load time. A base configuration can define shared consts for every DAG.
Unqualified Variables
$NAME and ${NAME} have no namespace, so the field decides who expands them:
| Field | Who expands $NAME and ${NAME} |
|---|---|
run | The shell or script interpreter, at run time. Dagu leaves the text as written. |
Root env values, dotenv paths, eval | Dagu, from the run scope, falling back to the host process environment. |
Step env, with inputs, working_dir, stdin, stdout, container fields, sub-DAG params | Dagu, from the run or step scope only. A name not in scope stays as written. |
template.render with.template | No one in Dagu. Pass values through with.data. |
params[].default, runtime overrides, secrets keys | No one. The text is literal. |
To bring a host variable into a workflow, import it in root env, then read it with ${env.NAME}:
env:
- AWS_REGION: ${AWS_REGION}
steps:
- id: list
run: aws --region "${env.AWS_REGION}" s3 lsInside run, use shell syntax for values the shell owns: loop variables, ${VAR:-default}, arrays, and command substitution.
Step Properties
Before declared outputs existed, steps were read through properties of their id. These forms still work and are useful for logs and exit codes:
| Form | Value |
|---|---|
${ID.stdout}, ${ID.stderr} | Path of the step's stdout or stderr log file |
${ID.exit_code} | Exit code of the finished step |
${ID.output}, ${ID.output.PATH} | Captured output, or a JSON path into it |
${ID.outputs}, ${ID.outputs.PATH} | Everything the step published on its outputs channel, or a JSON path into it |
${NAME.PATH} | A JSON path into a variable that holds JSON, such as an output: NAME variable |
${ID.stdout:0:20} takes a substring: start offset, then optional length. For new values passed between steps, declare outputs and use ${steps.ID.outputs.NAME}. Dagu validates that form and infers the dependency from it. See Outputs for how the strict and JSON path forms differ.
Fields That Resolve References
References resolve only in value-resolved fields. The common ones:
- Root
env,dotenvpaths,working_dir,shell,shell_args,container,ssh, and map-formworker_selector - Root and step
preconditions[].condition - Step
run,with(every nested string),env,working_dir,container,stdin,stdout,stderr, and artifact paths - String forms of
retry_policy.limit,retry_policy.interval_sec, and therepeat_policynumbers andcondition parallelitems,foreachitems andcollect, sub-DAGwith.dagandwith.params- Lifecycle handler steps
Identity and control fields stay literal: name, description, id, depends, action, timeout_sec, continue_on, outputs[].name, and the root run-control fields. A reference cannot pick a step, a dependency, or an action.
Dynamic evaluation runs only in params[].eval and precondition eval. Dagu resolves references first, then runs $(...) and backtick commands through the shell and inserts their trimmed stdout. A failed command is an error, except in a params[].eval that has a default, which falls back to the default.
Variable Precedence
When the same name comes from several sources, the later source in this list wins. The run scope is built once at run start:
- Host process environment, filtered
- Runtime profile defaults: Global, then workspace
- Parameters
- Root
env(base configuration entries first), then dotenv files - Selected runtime profile variables
- Dagu-managed run variables such as
DAG_RUN_ID(protected) - Selected runtime profile secrets
- DAG
secrets
Each step adds its own layers on top:
output: NAMEvariables from finished upstream steps- Step
env - Container
envandenv_file - Per-attempt values such as
DAG_RUN_STEP_STDOUT_FILEandDAGU_OUTPUT_FILE
So a secret overrides a DAG env value of the same name, and a step env entry overrides both for that step. Root env, dotenv, and profile values never replace the protected DAG_* run variables. See Runtime Profiles for how default and selected profiles combine.
Unresolved References
A reference that is valid but has no value, such as a param nobody supplied or an output of a skipped step, stays in the field as written. The run does not fail on it, but whatever reads the field sees the literal ${...} text.
steps:
- id: literal_text
run: echo '${not.a.supported.reference}'- Braced text that is not a supported form, like the example above, is plain text and is never reported.
dagu validatereports references that no run can resolve, such as an unknown step id or a typo undercontext. Pass--show-unresolvedto also list references that only have a value during a run.stdinis the exception: a path that still holds a reference, or resolves to an empty value, fails the step. See Standard Input.- A typed field can still fail on the leftover text, for example a retry
limitthat is not a number.
Dagu inserts each value once and does not scan it again, so a value that contains ${...} stays as text.
Escaping a Reference
Put a backslash before the $ to pass a Dagu reference through as literal text. Dagu removes the backslash.
steps:
- id: script
run: |
node - <<'JS'
console.log('\${steps.build.outputs.image}')
JSPath fields are the exception: there a backslash is a path separator, so C:\out\${params.name}.log resolves. See Quoting and Escaping for path fields, YAML double quotes, and shell quoting.
Related Pages
- Runtime Variables:
${context.*}andDAG_*variables - Quoting and Escaping: quotes, backslashes, and untrusted values
- Data and Variables: choosing where a value comes from
- Outputs: declaring and reading step outputs
- YAML Specification: every field

