Workflow Basics
Learn the fundamentals of writing Dagu workflows.
Your First Workflow
Create hello.yaml:
steps:
- run: echo "Hello from Dagu!"Run it:
dagu start hello.yamlWorkflow Structure
A complete workflow contains:
# Metadata
name: data-pipeline
description: Process daily data
labels: [etl, production]
# Configuration
schedule: "0 2 * * *"
params:
- DATE: "2026-03-14"
env:
- RUN_DATE: "`date +%Y-%m-%d`"
# Steps
tools:
- astral-sh/uv@0.11.14
steps:
- id: process
run: uv run --python 3.13.9 python process.py ${DATE} ${RUN_DATE}
# Handlers
handler_on:
failure:
run: notify-error.shSteps
The basic unit of execution.
Step Names
Step names are optional. When omitted, Dagu automatically generates names based on the action:
steps:
- run: echo "First step" # Auto-named: cmd_1
- run: | # Auto-named: cmd_2
echo "Multi-line"
echo "Script"
- id: explicit_name # Explicit name
run: echo "Third step"
- action: http.request # Auto-named: http_4
with:
method: GET
url: https://api.example.com
- action: template.render # Auto-named: template_5
with:
template: "Hello, {{ .name }}!"
data:
name: Dagu
- action: dag.run # Auto-named: dag_6
with:
dag: child-workflowAuto-generated names follow the pattern {executor}_{number}:
cmd_N- single-linerunstepsscript_N- multi-linerunstepshttp_N-http.requestactionstemplate_N-template.renderactionsdag_N-dag.runactionscontainer_N- Docker/container actionsssh_N-ssh.runactionsmail_N-mail.sendactionsjq_N-jq.filteractions
For parallel steps (see below), the pattern is parallel_{group}_{executor}_{index}.
Shell Commands
Use run for shell commands and scripts:
tools:
- astral-sh/uv@0.11.14
steps:
- run: echo "Hello World"
- run: ls -la
- run: uv run --python 3.13.9 python script.pyThis is equivalent to:
type: graph
tools:
- astral-sh/uv@0.11.14
steps:
- id: step_1
run: echo "Hello World"
- id: step_2
run: ls -la
depends: step_1
- id: step_3
run: uv run --python 3.13.9 python script.py
depends: step_2Multiple Commands
Multiple commands share the same step configuration:
tools:
- nodejs/node@v22.21.1
steps:
- id: build_and_test
run: |
npm install
npm run build
npm test
env:
- NODE_ENV: production
working_dir: /app
retry_policy:
limit: 3Instead of duplicating env, working_dir, retry_policy, preconditions, container, etc. across multiple steps, combine commands into one step.
Commands run in order and stop on first failure. Retries restart from the first command.
Trade-off: You lose the ability to retry or resume from the middle of the command list. If you need granular control over individual command retries, use separate steps.
For non-shell work, use an explicit action and put action-specific inputs under with.
Multi-line Scripts
tools:
- astral-sh/uv@0.11.14
steps:
- run: |
#!/bin/bash
set -e
echo "Processing..."
uv run --python 3.13.9 python analyze.py data.csv
echo "Complete"If you omit shell, Dagu uses the interpreter declared in the script's shebang (#!) when present.
Shell Selection
Set a default shell for every step at the DAG level, and override it per step when needed:
shell: ["/bin/bash", "-e", "-u"] # Default shell + args for the whole workflow
steps:
- id: bash_task
run: echo "Runs with bash -e -u"
- id: zsh_override
run: echo "Uses zsh instead"
with:
shell: /bin/zsh # Step-level overrideThe shell value accepts either a string ("bash -e") or an array (["bash", "-e"]). Arrays avoid quoting issues when you need multiple flags.
When you omit a step-level shell, Dagu runs through the DAG shell (or system default) and automatically adds -e on Unix-like shells so scripts stop on first error. If you explicitly set shell on a step, include -e yourself if you want the same errexit behavior.
tools:
- astral-sh/uv@0.11.14
steps:
- run: |
import pandas as pd
df = pd.read_csv('data.csv')
print(df.head())
with:
shell: uv run --python 3.13.9 pythonDependencies
tools:
- astral-sh/uv@0.11.14
steps:
- id: download
run: wget data.csv
- id: process
run: uv run --python 3.13.9 python process.py
depends: download
- id: upload
run: aws s3 cp output.csv s3://bucket/
depends: processParallel Execution
You can run steps in parallel using explicit dependencies:
type: graph
steps:
- id: setup
run: echo "Setup"
- id: task1
run: echo "Task 1"
depends: setup
- id: task2
run: echo "Task 2"
depends: setup
- id: finish
run: echo "All tasks complete"
depends: [task1, task2]Working Directory
Set where commands execute:
tools:
- astral-sh/uv@0.11.14
steps:
- id: in_project
working_dir: /home/user/project
run: uv run --python 3.13.9 python main.py
- id: in_data
working_dir: /data/input
run: ls -laEnvironment Variables
Define environment variables at DAG-level or step-level:
env:
- API_KEY: secret123
- ENV: production
steps:
- id: dev_test
run: echo "Running in $ENV"
env:
- ENV: development # Overrides DAG-levelTIP
Dagu filters system environment variables for security. See Environment Variables for details on filtering, inheritance, and .env file support.
Capturing Output
Store command output in variables:
steps:
- id: get_version
run: git rev-parse --short HEAD
output: VERSION
- id: build
run: docker build -t app:${VERSION} .
depends: get_versionBasic Error Handling
Continue on Failure
steps:
- id: optional_step
run: maybe-fails.sh
continue_on:
failure: true
- id: always_runs
run: cleanup.sh
depends: optional_stepSimple Retry
steps:
- id: flaky_api
run: curl https://unstable-api.com
retry_policy:
limit: 3Timeouts
Prevent steps from running forever:
steps:
- id: long_task
run: echo "Processing data"
timeout_sec: 300 # 5 minutesStep Descriptions
Document your steps:
tools:
- astral-sh/uv@0.11.14
steps:
- id: etl_process
description: |
Extract data from API, transform to CSV,
and load into data warehouse
run: uv run --python 3.13.9 python etl.pyLabels and Organization
Group related workflows:
name: customer-report
labels:
- reports
- customer
- daily
group: Analytics # UI groupingSee Also
- Control Flow - Conditionals and loops
- Data & Variables - Pass data between steps
- Error Handling - Advanced error recovery
- Parameters - Make workflows configurable
