Run a command after another command fails

To run another command if an earlier one fails you can use the following bash syntax

YOUR_COMMAND || (OTHER_COMMAND && exit 1)

This will still fail the build, but will let you execute another command first. If you are looking for a more flexible solution, take a look at ensure_called.sh.

Need More Help?

Get in touch if you need more help, or post on Stack Overflow using the tag #Codeship.

  • Ask The Helpdesk A Question
  • Code Examples And Sample Projects
    • Was This Article Helpful?