[PATCH openbmc-build-scripts v2] build-setup: Ensure we fail the build when a step fails

OpenBMC Patches openbmc-patches at stwcx.xyz
Mon Feb 15 11:10:21 AEDT 2016


From: Joel Stanley <joel at jms.id.au>

Currently the build step can fail inside docker but we don't propogate
that error up, so the Jenkins build will not be marked as failed.

We set the following options:

 set -xeuo pipefail

 - bash trace output (-x)
 - failing when a step fails (-e)
 - failing on undefined variables (-u)
 - failing when a command in a pipe fails (-o pipefail) - the default
 behaviour is to use the exit code of the final command in the pipe.

http://redsymbol.net/articles/unofficial-bash-strict-mode/

Thanks to Daniel Axtens <dja at axtens.net> for the extra suggestions.

Signed-off-by: Joel Stanley <joel at jms.id.au>
---
 build-setup.sh | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/build-setup.sh b/build-setup.sh
index a96ed44..9c156f7 100755
--- a/build-setup.sh
+++ b/build-setup.sh
@@ -7,8 +7,8 @@
 #   distro = fedora|ubuntu
 #   WORKSPACE = 
 
-# Trace bash processing
-set -x
+# Trace bash processing. Set -e so when a step fails, we fail the build
+set -xeuo pipefail
 
 # Default variables
 target=${target:-qemu}
@@ -85,10 +85,6 @@ fi
 
 # Build the docker container
 docker build -t openbmc/${distro} - <<< "${Dockerfile}"
-if [[ "$?" -ne 0 ]]; then
-  echo "Failed to build docker container."
-  exit 1
-fi
 
 # Create the docker run script
 export PROXY_HOST=${http_proxy/#http*:\/\/}
@@ -100,7 +96,7 @@ mkdir -p ${WORKSPACE}
 cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
 #!/bin/bash
 
-set -x
+set -xeuo pipefail
 
 cd ${WORKSPACE}
 
-- 
2.7.1




More information about the openbmc mailing list