Argo stop workflow early, mark complete

2/4/2021

Imagine I have a workflow with 5 steps.

Step 2 may or may not create a file as its output (which is then used as input to subsequent steps).

  • If the file is created, I want to run the subsequent steps.
  • If no file gets created in step 2, I want to mark the workflow as completed and not execute steps 3 through to 5.

I'm sure there must be a simple way to do this yet I'm failing to figure out how.

I tried by making step 2 return non-zero exit code when no file is created and then using when: "{{steps.step2.outputs.exitCode}} == 0" on step 3, but that still executes step 4 and 5 (not to mention marks step 2 as "failed")

So I'm out of ideas, any suggestions are greatly appreciated.

-- Krzysztof Kozmic
argo-workflows
argoproj
kubernetes

1 Answer

2/5/2021

By default, a step that exits with a non-zero exit code fails the workflow.

I would suggest writing an output parameter to determine whether the workflow should continue.

- name: yourstep
  container:
    command: [sh, -c]
    args: ["yourcommand; if [ -f /tmp/yourfile ]; then echo continue > /tmp/continue; fi"]
  outputs:
    parameters:
    - name: continue
      valueFrom:
        default: "stop"
        path: /tmp/continue

Alternatively, you can override the fail-on-nonzero-exitcode behavior with continueOn.

continueOn:
  failed: true

I'd caution against continueOn.failed: true. If your command throws a non-zero exit code for an unexpected reason, the workflow won't fail like it should, and the bug might go un-noticed.

-- crenshaw-dev
Source: StackOverflow