Skip to main content

Is there a way to fail a build when one of the build hooks throws an error?

Comments

2 comments

  • Platform.sh DevRel

    Yes. To do this you need to start your build hook with set -e. That means :

      -e  Exit immediately if a command exits with a non-zero status.
    
    0
  • florian

    To be a bit more clear, if you don’t use set -e, the build will exit with the exit code of the last command.

    For example:

    ls /folder/that/doesnt/exist
    exit 0
    

    Will exit with exit code “0”, for success. If you use set -e, the build will exit after the ls with the exit code that ls failed with.

    Another option that is usually useful is set -o pipefail which will fail the build if a piped command fails.

    For example:

    set -e
    ls /folder/that/doesnt/exist | echo foo
    exit 0
    

    Will return with exit code 0.

    set -eo pipefail
    ls /folder/that/doesnt/exist | echo foo
    exit 0
    

    Will return with a failure.

    0

Please sign in to leave a comment.