Task with loop in Argo workflow

2k Views Asked by At

I want to introduce a for loop in a workflow that consists of 2 individual tasks. The second will be dependent on the first. Each one should use different templates. The second should iterate with {{item}}. For each iteration I want to know if the default is to execute only the second task or it will re-execute the whole flow?

2

There are 2 best solutions below

1
On

To repeat the second step only, use withItems/withParameter (there is no withArtifact, though you can get the same behavior with data). These loops repeat the specific step they are mentioned in for the specified items/parameter only.

3
On
- name: create-resources
  inputs:
      paramet`enter code here`ers:
        - name: env
        - name: giturl
        - name: resources
        - name: awssecret
  dag:
    tasks:
      - name: resource
        template: resource-create
        arguments:
          parameters:
          - name: env
            value: "{{inputs.parameters.env}}"
          - name: giturl
            value: "{{inputs.parameters.giturl}}"  
          - name: resource
            value: "{{item}}"
          - name: awssecret
            value: "{{inputs.parameters.awssecret}}"   
        withParam: "{{inputs.parameters.resources}}"
        #############   For parallel execution use steps ##############
  steps:
  - - name: resource
      template: resource-create
      arguments:
        parameters:
        - name: env
          value: "{{inputs.parameters.env}}"
        - name: giturl
          value: "{{inputs.parameters.giturl}}"  
        - name: resource
          value: "{{item}}"
        - name: awssecret
          value: "{{inputs.parameters.awssecret}}"   
      withParam: "{{inputs.parameters.resources}}"