Skip to content

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: consts resolve while the DAG file is read. They can only reference earlier consts.
  • Run start: parameters, eval defaults, dates, the runtime profile, secrets, root env, 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 ​

FormReadsResolvesDetails
${consts.name}An immutable value from root constsLoadConstants
${params.name}A named parameterRun startParameters
${params}All resolved parameters as one JSON string, same as DAG_PARAMS_JSONRun startParameter Payload
${env.NAME}A value from the current environment scopeRun start or step startEnvironment Variables
${dates.NAME}A date derived from the run's schedule slotRun startSchedule Dates
${context.run.id}Run, attempt, step, trigger, path, profile, or push-back metadataRun start or step startRuntime Variables
${steps.ID.outputs.NAME}A declared output of a finished stepStep startOutputs
${foreach.item}, ${foreach.index}, ${foreach.key}The current item in a foreach bodyStep startForeach
${inputs.NAME}, ${outputs.NAME}Input and staging paths in a type: build stepStep startBuild Workflows
${node.name}The node a bound run runs onRun startNode Targeting
$NAME, ${NAME}Unqualified environment syntaxDepends on the fieldUnqualified 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.

yaml
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.

yaml
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:

FieldWho expands $NAME and ${NAME}
runThe shell or script interpreter, at run time. Dagu leaves the text as written.
Root env values, dotenv paths, evalDagu, from the run scope, falling back to the host process environment.
Step env, with inputs, working_dir, stdin, stdout, container fields, sub-DAG paramsDagu, from the run or step scope only. A name not in scope stays as written.
template.render with.templateNo one in Dagu. Pass values through with.data.
params[].default, runtime overrides, secrets keysNo one. The text is literal.

To bring a host variable into a workflow, import it in root env, then read it with ${env.NAME}:

yaml
env:
  - AWS_REGION: ${AWS_REGION}

steps:
  - id: list
    run: aws --region "${env.AWS_REGION}" s3 ls

Inside 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:

FormValue
${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, dotenv paths, working_dir, shell, shell_args, container, ssh, and map-form worker_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 the repeat_policy numbers and condition
  • parallel items, foreach items and collect, sub-DAG with.dag and with.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:

  1. Host process environment, filtered
  2. Runtime profile defaults: Global, then workspace
  3. Parameters
  4. Root env (base configuration entries first), then dotenv files
  5. Selected runtime profile variables
  6. Dagu-managed run variables such as DAG_RUN_ID (protected)
  7. Selected runtime profile secrets
  8. DAG secrets

Each step adds its own layers on top:

  1. output: NAME variables from finished upstream steps
  2. Step env
  3. Container env and env_file
  4. Per-attempt values such as DAG_RUN_STEP_STDOUT_FILE and DAGU_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.

yaml
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 validate reports references that no run can resolve, such as an unknown step id or a typo under context. Pass --show-unresolved to also list references that only have a value during a run.
  • stdin is 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 limit that 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.

yaml
steps:
  - id: script
    run: |
      node - <<'JS'
      console.log('\${steps.build.outputs.image}')
      JS

Path 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.

Dagu is open source under the GNU General Public License v3.0.