Stop build EC2 AMI image if script fails

12 views
Skip to first unread message

Giorgio Cerruti

unread,
Jun 19, 2020, 4:18:40 AM6/19/20
to Packer
Hi there,
I'm new to packer and I facing this issue. Basically, my workflow is to upload a bash script within the EC2 made by packer to install the stack I need to run my application. Now, sometimes something happens and the script fails to exit with an error code not equal 0, but packer still creating the AMI. How can I modify this behavior letting packer stops to build the AMI? I need this because of my CI/CD pipeline. Moreover, I added the `set -e` into my bash script.

Thanks in advance.


dragon788

unread,
Jun 22, 2020, 11:22:36 AM6/22/20
to Packer
You say the script "fails to exit with an error code not equal to 0". So it is failing, and you have `set -e` but you aren't seeing Packer detect that it failed?

Try `set -euo pipefail` instead of just `set -e`.

Reply all
Reply to author
Forward
0 new messages