Parameters and Outputs
Parameters are a workflow's inputs, set each time it starts. Outputs carry a value from one step to the steps after it.
The workflow
bash
curl -fsSLO https://docs.dagu.sh/tutorial/dags/tutorial-03-params-and-outputs.yamlyaml
# Dagu tutorial, lesson 3: https://docs.dagu.sh/tutorial/params-and-outputs
description: Take inputs and pass a value from one step to the next
type: graph
params:
- name: environment
type: string
enum: [dev, staging, prod]
default: dev
- name: version
type: string
default: "1.0.0"
steps:
- id: build
run: echo "app-${params.version}.tar.gz"
output:
bundle:
from: stdout
- id: deploy
run: echo "Deploying ${steps.build.outputs.bundle} to ${params.environment}"
depends: buildparamsdeclares two inputs.environmentaccepts only the three listed values. Both have a default, so the workflow also runs with no input.${params.version}inserts a parameter's value into a command.outputonbuildpublishes the step's printed text as an output namedbundle.${steps.build.outputs.bundle}reads that output in a later step. The reading step must depend onbuild.
Watch it run
deployrunSucceeded
Deploying app-1.0.0.tar.gz to dev
Select build to see the bundle output it published.
Run it yourself
Run it with the defaults, then with your own values after --:
bash
dagu start tutorial-03-params-and-outputs.yaml
dagu start tutorial-03-params-and-outputs.yaml -- environment=staging version=2.1.0deploy prints Deploying app-2.1.0.tar.gz to staging.
In the Web UI, Start opens a dialog with one field per parameter. environment is a list with the three allowed values.
Try it
- Run with
environment=qa. What happens? - Add a third step,
notify, that printsShipped <bundle>using the output ofbuild.
Answers
- Dagu rejects the input before any step runs, because
qais not one of the allowed values. - Add this step to
steps:
yaml
- id: notify
run: echo "Shipped ${steps.build.outputs.bundle}"
depends: build
