Argo Workflows条件判断:如何根据输出含字符串触发第二步?
Argo流水线条件触发:基于步骤输出的子字符串匹配
要实现第一步输出包含指定子字符串时触发第二步,你需要修正when表达式的参数引用语法,并确保contains函数的使用符合Argo Workflows规则,具体操作如下:
核心修正
- 步骤输出引用格式:必须添加
steps.前缀,正确格式为steps.<步骤名>.outputs.parameters.<参数名> - contains函数参数顺序:第一个参数是待检查的目标字符串,第二个是要匹配的子字符串
修正后的完整代码片段
- - name: 1-first-step template: 1-first-step # 需确保该步骤模板中正确定义outputs.parameters.output_json_list,输出内容为 "[{\"A\":\"Joe\", \"B\":\"Bob\"}]" - - name: 2-second-step templateRef: name: 2-second-step template: main arguments: parameters: - name: Some_name value: "Some_value" when: "{{contains steps.1-first-step.outputs.parameters.output_json_list 'Joe'}}"
补充说明
- 第一步模板的输出参数定义:要让
output_json_list能被正确引用,需在1-first-step模板中明确输出参数,示例:
templates: - name: 1-first-step script: image: alpine:3.18 command: [sh] source: | # 模拟输出JSON字符串 echo '[{"A":"Joe", "B":"Bob"}]' > /tmp/result.json outputs: parameters: - name: output_json_list valueFrom: path: /tmp/result.json
- 复杂JSON字段匹配:如果需要针对JSON中的特定字段做匹配,可先用
jsonPath解析后再判断,比如仅匹配A字段等于Joe的场景:
when: "{{eq (jsonPath steps.1-first-step.outputs.parameters.output_json_list '[0].A') 'Joe'}}"
内容的提问来源于stack exchange,提问作者Jh123
相关产品推荐
相关产品推荐

