I'm attempting to use Argo to loop through an array of JSON objects however the workflow is returning:
failed to resolve {{item}} 
The workflow configuration is as follows:
- name: output-parameter
   steps:
    - - name: generate-parameter
        template: getresult
    - - name: consume-parameter
         template: print-result
         arguments:
           parameters:          
           - name: result
           value: "{{item}}"
         withParam: "{{steps.generate-parameter.outputs.result}}"      
 - name: getresult
   script:
     image: python:alpine3.6
     command: [python]
     source: |        
       import json
       import sys
       json.dump([{"name":"Foo"},{"name":"Doe"}], sys.stdout)
 - name: print-result
   inputs:
     parameters:
     - name: result
   container:
     image: crweu.azurecr.io/ubuntu_run:v1.0.6
     command: [sh, -c]
     args: ["echo {{inputs.parameters.result}}"]
If I used the example argo loop with:
json.dump([i for i in range(20, 31)], sys.stdout)
It prints out the number range without issues.
I assume the problem is due to the fact it's not a simple item it's an object and the {{item}} needs to change but I am unable to find any documentation on it.
You need to adjust the arguments of the consume-parameter step to:
         arguments:
           parameters:          
           - name: result
             value: "{{item.name}}"
         withParam: "{{steps.generate-parameter.outputs.result}}"      
This is because Argo is parsing the JSON output of the getresult step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With