4
apiVersion: argoproj.io/v1alpha1
kind: Workflow
.
.
  - name: mytemplate
    steps:
    - - name: mytask
        templateRef:
          name: ABCDworkflowtemplate
          template: taskA
        arguments:
          parameters:
            - name: mylist
              value: [10,"some",false]  
....................
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: ABCDworkflowtemplate
 
spec:
  templates:
    - name: taskA
      inputs:
        parameters:
          - name: mylist
.

My question is how to use every element of this list {{input.parameters.?}} ? Help me with some reference. Thank you

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user18354658
  • 65
  • 1
  • 5

1 Answers1

2

You didn't really specify what exactly you want to do with these values so i'll explain both ways to use this input.

  1. The more common usage with arrays is to iterate over them using "withParam", With this syntax a new task (pod) will be created for each of the items.
  templates:
    - name: taskA
      inputs:
        parameters:
          - name: mylist
      steps:
        - - name: doSomeWithItem
            template: doSomeWithItem
            arguments:
              parameters:
                - name: item
                  value: "{{item}}"
            withParam: "{{inputs.parameters.mylist}}"

    - name: doSomeWithItem
      inputs:
        parameters:
          - name: item
      container:
        image: python:alpine3.6
        command: [ python ]
        source: |
          print("{{inputs.parameters.item}}")

Argo with param

The other option is just to pass the entire array as a variable to the pod, and use custom logic based on needs:

  templates:
    - name: taskA
      inputs:
        parameters:
          - name: mylist
      steps:
        - - name: doSomethingWithList
            template: doSomethingWithList
            arguments:
              parameters:
                - name: list
                  value: "{{inputs.parameters.mylist}}"

    - name: doSomethingWithList
      inputs:
        parameters:
          - name: list
      container:
        image: python:alpine3.6
        command: [ python ]
        source: |
          if (list[2] == 'some'):
            // do somehting
          else if (list[0] == 10]:
            // do something
Tom Slabbaert
  • 21,288
  • 10
  • 30
  • 43