Correctly fail in build-script

If a container image failed to build, the build-script did not always
report this. This was the case, if multiple images were built at the
same time and happened because a global variable was used to track
failures, which was not correctly reset between builds.

This change changes the method to detect return codes of the docker
build command, to detect build failures more consistently.

The success of `docker build`-commands is also tested in other parts of
the script. To stay consistent in how the success of the build is
determined, these instances were adapted accordingly, although these
were functioning as intended, since only one image was build at a time
for these cases.

Change-Id: I05a71e01bfbfa544a73701951d0f23c3016c21a9
diff --git a/build b/build
index a2cde51..16211d1 100755
--- a/build
+++ b/build
@@ -32,8 +32,8 @@
 docker_build(){
     IMAGE=$1
 
-    docker build -t k8sgerrit/$IMAGE:$TAG -t k8sgerrit/$IMAGE:$GIT_REV ./container-images/$IMAGE && BUILD_SUCCESS=1
-    if test -z "$BUILD_SUCCESS"; then
+    docker build -t k8sgerrit/$IMAGE:$TAG -t k8sgerrit/$IMAGE:$GIT_REV ./container-images/$IMAGE
+    if test $? -ne 0; then
         REPORT="$REPORT Failed: k8sgerrit/$IMAGE.\n"
         RETURN_CODE=1
     else
@@ -45,19 +45,21 @@
     if test -n "$GERRIT_WAR_URL"; then
         BUILD_ARGS="--build-arg GERRIT_WAR_URL=$GERRIT_WAR_URL"
     fi
-    docker build $BUILD_ARGS -t gerrit-base ./container-images/gerrit-base || {
+    docker build $BUILD_ARGS -t gerrit-base ./container-images/gerrit-base
+    if test $? -ne 0; then
         echo -e "\n\nFailed to build gerrit-base image."
         exit 1
-    }
+    fi
 }
 
 REPORT="Build results: \n"
 RETURN_CODE=0
 
-docker build -t base ./container-images/base || {
-            echo -e "\n\nFailed to build base image."
-            exit 1
-        }
+docker build -t base ./container-images/base
+if test $? -ne 0; then
+    echo -e "\n\nFailed to build base image."
+    exit 1
+fi
 
 if test $# -eq 0 ; then
     docker_build_gerrit_base