<p>Imagine I have a workflow with 5 steps.</p>
<p>Step 2 may or may not create a file as its output (which is then used as input to subsequent steps).</p>
<ul>
<li>If the file is created, I want to run the subsequent steps.</li>
<li>If no file gets created in step 2, I want to mark the workflow as completed and not execute steps 3 through to 5.</li>
</ul>
<p>I'm sure there must be a simple way to do this yet I'm failing to figure out how.</p>
<p>I tried by making step 2 return non-zero exit code when no file is created and then using
<code>when: &quot;{{steps.step2.outputs.exitCode}} == 0&quot;</code> on step 3, but that still executes step 4 and 5 (not to mention marks step 2 as &quot;failed&quot;)</p>
<p>So I'm out of ideas, any suggestions are greatly appreciated.</p>

Krzysztof Kozmic
<p>By default, a step that exits with a non-zero exit code fails the workflow.</p>
<p>I would suggest writing an <a href="https://github.com/argoproj/argo/blob/master/examples/output-parameter.yaml" rel="nofollow noreferrer">output parameter</a> to determine whether the workflow should continue.</p>
<pre class="lang-yaml prettyprint-override"><code>- name: yourstep
  container:
    command: [sh, -c]
    args: [&quot;yourcommand; if [ -f /tmp/yourfile ]; then echo continue &gt; /tmp/continue; fi&quot;]
  outputs:
    parameters:
    - name: continue
      valueFrom:
        default: &quot;stop&quot;
        path: /tmp/continue
</code></pre>
<p>Alternatively, you can <a href="https://github.com/argoproj/argo/blob/master/examples/exit-code-output-variable.yaml#L12" rel="nofollow noreferrer">override the fail-on-nonzero-exitcode behavior</a> with <code>continueOn</code>.</p>
<pre class="lang-yaml prettyprint-override"><code>continueOn:
  failed: true
</code></pre>
<p>I'd caution against <code>continueOn.failed: true</code>. 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.</p>
