Tutorials / Pass results between tasks with an approval
Verified against Flow 5.0.0-beta.39
This tutorial builds a workflow of three tasks. A shell task makes a file name from a parameter and returns it as a result, a Manual Approval waits for a person to decide, and a second shell task prints the file name and the decision. It's for workflow authors, takes about 15 minutes, and needs no accounts outside Flow.
You need:
| Task name | Task | What it does |
|---|---|---|
build |
Execute Shell | Makes my-app-<version>.tar.gz from the version parameter, and returns it as the result filename |
approve |
Manual Approval | Waits for someone to approve or reject, then records who decided and what they said |
publish |
Execute Shell | Prints filename and the approval's results |
Tasks read values through references, which Flow fills in before the task starts:
$(params.version) reads the workflow parameter version;$(tasks.build.results.filename) reads the result filename from the task named build.Publish with approval. Flow fills Name with publish-with-approval.version and the Label (optional) Version.1.0.0 as the Default value (optional).When a run starts, Flow asks for Version, with 1.0.0 filled in. Tasks read the value by the parameter's name, as $(params.version).
Note
Give the parameter a label. The dialog says an empty label shows the name, but in 5.0.0 a parameter without a label appears in Workflow Parameters as an unlabelled field.
Select the Canvas tab.
In Add a task, search for shell, and drag Execute Shell onto the canvas. It's in the Utilities category.
Select the node's edit (pencil) icon. Edit Execute Shell opens.
Set Task name to build.
Select the Shell Script field. In Update Shell Script, enter the script below, then select Update.
filename="my-app-$(params.version).tar.gz"
echo "Built $filename"
if [ -d "$RESULTS_PATH" ]; then
printf '%s' "$filename" > "$RESULTS_PATH/filename"
else
printf '{"filename":"%s"}' "$filename" > "$RESULTS_PATH"
fiUnder Result Parameters, enter the Name filename and the Description The file the build made. Add is available once both are filled. Select Add: the result appears below as filename:The file the build made.
Select Apply.
Flow replaces $(params.version) before the script runs, so with 1.4.2 the shell sees filename="my-app-1.4.2.tar.gz".
A script returns a result by writing it to the path in the RESULTS_PATH environment variable. Depending on how your operator set up the dispatcher, that path is a directory holding one file per result, or a single file holding a JSON object; the if covers both. Flow keeps only the results the node declares under Result Parameters, so declare every result your script writes. Develop a task has the details.
approve.The Results tab in Edit Manual Approval lists the five results the task records when someone decides. This tutorial uses three:
| Result | Value |
|---|---|
approvalStatus |
approved or rejected |
approvalUserName |
The name of the person who decided |
approvalComments |
Their comment, or empty |
The other two are approvalDate and approvalUserEmail. See Actions for all five.
Drag another Execute Shell onto the canvas. Flow names it Execute Shell 2.
Select its edit icon, and set Task name to publish.
Select the Shell Script field, enter the script below, then select Update.
echo "Publishing $(tasks.build.results.filename)"
echo "Decision: $(tasks.approve.results.approvalStatus) by $(tasks.approve.results.approvalUserName)"
echo "Comment: $(tasks.approve.results.approvalComments)"Select Apply. This task returns nothing, so leave Result Parameters empty.
Each reference names a task by its Task name, build or approve. If you rename a task later, update the references to it.
build. Link build to approve, approve to publish, and publish to End the same way.approve to publish, once. It changes from an arrow (always) to a tick (success): publish now runs only when approve succeeds, which it does when someone approves.First version, then select Create.Flow confirms "Successfully created workflow version".

1.4.2, then select Run and View.The run page opens, and Status shows Running. In the Task log, build shows Succeeded once its container has run, usually within a minute. Then approve shows Waiting, with an Action button. The run waits there until someone decides, and the wait doesn't count towards the run's timeout.
To see the result build returned, select View Details under build. Results lists filename, its description, and the value my-app-1.4.2.tar.gz. Params shows the script as it ran, with $(params.version) already replaced by 1.4.2.
approve, status Waiting, and 0/1 approvals.Checked the release notes.Flow confirms "Success! Request to approve action submitted".

You can decide from the run page instead: select Action on approve, then in Action Manual Approval select Approve, add a comment and select Submit.
Return to the run: select Activity in the side nav, then the run's row.
Wait for publish and End to show Succeeded. The run's Status then reads Succeeded, with its active time.

Under publish, select View Log. The Execution Log ends with these lines, with your name in place of Grace Hopper's:
Publishing my-app-1.4.2.tar.gz
Decision: approved by Grace Hopper
Comment: Checked the release notes.
The lines above them come from the task's runner. Its warning Failed to get params is expected: the next lines show it read the parameters from environment variables instead.
publish read filename from build, which ran before the approval, and three results from approve. A result stays readable by every later task in the run, however long the run waited in between. To see who decided after the fact, select View Action under approve.
You've built a workflow that passes a parameter into a task, a result from one task to another, and a person's decision to the task after it.
A rejection ends approve Failed. It still records its results, with approvalStatus set to rejected. The link from approve to publish decides what happens next.
Link from approve to publish |
After Approve | After Reject |
|---|---|---|
| Success (tick), as built above | publish runs. The run ends Succeeded. |
publish shows Skipped. The run ends Failed. |
| Always (arrow) | publish runs. The run ends Succeeded. |
publish runs and prints Decision: rejected by Grace Hopper. The run ends Succeeded. |
To see the first case, run the workflow again, and in Action details select Reject instead of Approve. The run's Status reads Failed, because approve failed and the only path on from it needed a success. End still shows Succeeded in the task log.
To see the second:
approve to publish twice. Each select moves it on, from success to failure, then to always: the icon is an arrow again.This time publish runs and its log prints Decision: rejected by and your name. The run ends Succeeded, though approve shows Failed in the task log: an always link carries on past a failure, so the run reached its end.
Use a success link when the next task should happen only on approval, such as a release. Use an always link when the next task reports the outcome either way, and read approvalStatus in it to tell the two apart. A failure link runs the next task only on a rejection, for example to tell someone their request was turned down.
build stay Ready?publish fail with ParamUnresolved?