How to ignore a failure in a step

 

How to ignore a failure in a step:

In some instances, you may need a job to continue running even if a step returns a non zero exit code. This could be due to a subsequent dependent job in a workflow, or that the success of a step is not a contributing factor to the success of your pipeline.

Note: Use the following with caution. Ensure you absolutely need this functionality for the particular step. Otherwise, failures in your jobs may go unnoticed which may have knock-on effects.

 

The easiest way to implement this is to set up the step as follows:

- run: my_cool_command || true

This ensures that the step always returns a zero exit code, regardless of if the command fails or not.

 

If you have a mutli-line command, or a script file, then you may consider overriding the default shell options to ensure an exit code zero is passed:

- run:
shell: /bin/bash
command: |
echo Running my cool command
mkdir ~/some_dir
my_cool_command

For more details on how the default shell options work, and why they have been chosen as the default, please see our documentation.

 

Additional Resources:

Was this article helpful?
9 out of 45 found this helpful

Comments

0 comments

Article is closed for comments.