diff --git a/content/docs/04.workflow-components/06.outputs.md b/content/docs/04.workflow-components/06.outputs.md index 88d40321cf..90cbead086 100644 --- a/content/docs/04.workflow-components/06.outputs.md +++ b/content/docs/04.workflow-components/06.outputs.md @@ -107,6 +107,99 @@ tasks: from: "{{ outputs.output_from_query.uri }}" ``` +## Flow outputs + +::badge{version=">=0.15" editions="OSS,EE,Cloud"} +:: + +Since Kestra 0.15.0, the flow can also produce strongly typed outputs. You can add them using the `outputs` attribute in the flow definition. + +Here is an example of a flow that produces an output: + +```yaml +id: flow_outputs +namespace: company.team + +tasks: + - id: mytask + type: io.kestra.plugin.core.debug.Return + format: this is a task output used as a final flow output + +outputs: + - id: final + type: STRING + value: "{{ outputs.mytask.value }}" +``` + +You can see that outputs are defined as a list of key-value pairs. The `id` is the name of the output attribute (must be unique within a flow), and the `value` is the value of the output. You can also add a `description` to the output. + +You will see the output of the flow on the **Executions** page in the **Overview** tab. + +![subflow_output](/docs/workflow-components/subflow_output.png) + +### Pass data between flows using flow outputs + +Here is how you can access the flow output in a parent flow: + +```yaml +id: parent_flow +namespace: company.team + +tasks: + - id: subflow + type: io.kestra.plugin.core.flow.Subflow + flowId: flow_outputs + namespace: company.team + wait: true + + - id: log_subflow_output + type: io.kestra.plugin.core.log.Log + message: "{{ outputs.subflow.outputs.final }}" +``` + +In the example above, the `subflow` task produces an output attribute `final`. This output attribute is then used in the `log_subflow_output` task. + +::alert{type="info"} +Note how the `outputs` are set twice within the `"{{outputs.subflow.outputs.final}}"`: +1. once to access outputs of the `subflow` task +2. once to access the outputs of the subflow itself — specifically, the `final` output. +:: + +Here is what you will see in the **Outputs** tab of the **Executions** page in the parent flow: + +![subflow_output_parent](/docs/workflow-components/subflow_output_parent.png) + +### Return outputs conditionally + +Sometimes you may want to return different outputs based on a condition. For instance, if a given task is skipped, you may want to return a fallback value or return the output of another task. Here is an example of how you can achieve this: + +```yaml +id: conditionally_return_output +namespace: company.team + +inputs: + - id: run_task + type: BOOLEAN + defaults: true + +tasks: + - id: main + type: io.kestra.plugin.core.debug.Return + format: Hello World! + runIf: "{{ inputs.run_task }}" + + - id: fallback + type: io.kestra.plugin.core.debug.Return + format: fallback output + +outputs: + - id: flow_output + type: STRING + value: "{{ tasks.main.state != 'SKIPPED' ? outputs.main.value : outputs.fallback.value }}" +``` + +Note how the Ternary Operator `{{ condition ? value_if_true : value_if_false }}` is used in the output expression `{{ tasks.main.state != 'SKIPPED' ? outputs.main.value : outputs.fallback.value }}` to return the output of the `main` task if it is not skipped, otherwise, it returns the output of the `fallback` task. + ## Dynamic variables (Each tasks) ### Current taskrun value @@ -244,62 +337,7 @@ The latter can become very complex when parents exist (multiple imbricated EachS Accessing sibling task outputs is impossible on [Parallel](/plugins/core/tasks/flows/io.kestra.plugin.core.flow.Parallel) or [EachParallel](/plugins/core/tasks/flows/io.kestra.plugin.core.flow.EachParallel) as they run tasks in parallel. :: -## Pass data between flows using flow outputs - -Since 0.15.0, the flow can also produce strongly typed outputs simply by defining them in the flow file. Here is an example of a flow that produces an output: - -```yaml -id: flow_outputs -namespace: company.team - -tasks: - - id: mytask - type: io.kestra.plugin.core.debug.Return - format: this is a task output used as a final flow output - -outputs: - - id: final - type: STRING - value: "{{ outputs.mytask.value }}" -``` - -You can see that outputs are defined as a list of key-value pairs. The `id` is the name of the output attribute (must be unique within a flow), and the `value` is the value of the output. You can also add a `description` to the output. - -You will see the output of the flow on the **Executions** page in the **Overview** tab. - -![subflow_output](/docs/workflow-components/subflow_output.png) - -Here is how you can access the flow output in the parent flow: - -```yaml -id: parent_flow -namespace: company.team - -tasks: - - id: subflow - type: io.kestra.plugin.core.flow.Subflow - flowId: flow_outputs - namespace: company.team - wait: true - - - id: log_subflow_output - type: io.kestra.plugin.core.log.Log - message: "{{ outputs.subflow.outputs.final }}" -``` - -In the example above, the `subflow` task produces an output attribute `final`. This output attribute is then used in the `log_subflow_output` task. - -::alert{type="info"} -Note how the `outputs` are set twice within the `"{{outputs.subflow.outputs.final}}"`: -1. once to access outputs of the `subflow` task -2. once to access the outputs of the subflow itself — specifically, the `final` output. -:: - -Here is what you will see in the **Outputs** tab of the **Executions** page in the parent flow: - -![subflow_output_parent](/docs/workflow-components/subflow_output_parent.png) - -## Outputs Preview ## +## Outputs Preview Kestra provides preview option for output files that get stored on Kestra internal storage. Lets see this with the help of the following flow: @@ -321,7 +359,7 @@ On clicking the Preview button, you can preview the contents of the file in a ta ![preview](/docs/workflow-components/outputs/preview.png) -## Using Debug Outputs ## +## Using Debug Outputs You can evaluate the output further using the **Debug Outputs** functionality in the **Outputs** tab. Consider the following flow: