modernisation-platform icon indicating copy to clipboard operation
modernisation-platform copied to clipboard

Use 'set -Eeuo pipefail' in bash scripts

Open gfou-al opened this issue 3 years ago • 0 comments

User Story

The issue https://github.com/ministryofjustice/modernisation-platform/issues/1166 highlighted the fact that some scripts continue to run instead of exiting with error code. This means that the GitHub job reports success while there are fatal errors during the execution. To fix this issue we need to set set -Eeuo pipefail in the beginning of the script, as documented in https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/

Unfortunately, a lot of our bash scripts under the scripts directory in the modernisation-platform repository have the same issue. Perhaps it would make sense to proactively update all/most of them to use set -Eeuo pipefail, unless some of them require otherwise due to their logic. Talk to @davidkelliott as there are some scripts which might need to continue upon failure, or might need to be refactored to deal with "expected" error codes.

Value

Questions / Assumptions

Definition of done

  • [ ] readme has been updated
  • [ ] user docs have been updated
  • [ ] another team member has reviewed
  • [ ] tests are green

Reference

How to write good user stories

gfou-al avatar Oct 18 '21 10:10 gfou-al