How can I get sub workflow steps/tasks output?

2.8k Views Asked by At

I created a cluster workflow template, which will do some tasks. And I will use last step output as current workflow parameters. When I ref this template, I don't know how can I get the output from cluster workflow task/step.

Cluster Workflow Template

apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
  name: gen-params
spec:
  templates:
  - name: tasks
    steps:
    - - name: prepare
        template: prepare
    - - name: gen-params
        template: gen-params
...     

Workflow

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  name: demo
spec:
  entrypoint: main
  templates:
  - name: main
    steps:
    - - name: gen-params
        templateRef:
          name: gen-params
          template: tasks
          clusterScope: true
    - - name: calculate
        template: calculate
        arguments:
          parameters:
          - name: params
            value: "{{steps.gen-params.steps.gen-params.outputs.result}}"  # not work
...
2

There are 2 best solutions below

1
On BEST ANSWER

Your issue is likely less about the usage of a WorkflowTemplate/ClusterWorkflowTemplate and more to do with the fact that you are attempting to access output from a "nested" workflow step.

You can achieve this by defining an output parameter of the top-level tasks template in your ClusterWorkflowTemplate which takes its value from the output result of the last step in that tasks template.

Your WorkflowTemplate would look like this:

apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
  name: gen-params
spec:
  templates:
  - name: tasks
    steps:
    - - name: prepare
        template: prepare
    - - name: gen-params
        template: gen-params
    outputs:
        parameters:
          - name: "nested-gen-params-result"
            valueFrom:
              parameter: "{{steps.gen-params.outputs.result}}"

After making that change, you'll be able reference the output of the ClusterWorkflowTemplate-defined step of your top-level Workflow using {{steps.gen-params.outputs.parameters.nested-gen-params-result}}

Argo's nested-workflow example shows some other similar patterns.

4
On

templateRef is simply a link, used to populate the YAML of the Workflow step. You should interact with the gen-params step in the same way that you would if you'd just copy/pasted the YAML from the gen-params ClusterWorkflowTemplate directly into your new Workflow.

In this case, you should access the result of the gen-params step with this: {{steps.gen-params.outputs.result}}.