A when clause conditionally executes an Argo Workflows step based on an expression. It connects a prior step's output to the next step's execution path. section 8.4.1
Branching on a coin flip
Run flip-coin first, then select heads or tails by comparing its result: when: "{{steps.flip-coin.outputs.result}} == heads". Only the matching step runs, producing two Pods for the workflow. section 8.4.1
Listing 8.52 Coin-flip example
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: coinflip-
spec:
serviceAccountName: argo
entrypoint: coinflip
templates:
- name: coinflip
steps:
- - name: flip-coin
template: flip-coin
- - name: heads
template: heads
when: "{{steps.flip-coin.outputs.result}} == heads"
- name: tails
template: tails
when: "{{steps.flip-coin.outputs.result}} == tails"
- name: flip-coin
script:
image: python:alpine3.6
command: [python]
source: |
import random
result = "heads" if random.randint(0,1) == 0 else "tails"
print(result)
- name: heads
container:
image: alpine:3.6
command: [sh, -c]
args: ["echo \"it was heads\""]
- name: tails
container:
image: alpine:3.6
command: [sh, -c]
args: ["echo \"it was tails\""]
Inspect a complete Argo workflow showing paired conditional steps, templates, output interpolation, and the preceding script step. section 8.4.1
