Don't try to pushd into dir that doesn't exist
[releng/global-jjb.git] / .jjb-test / expected-xml / github-ciman-packer-merge-ubuntu1604-java-builder
index 35b4aaa..02cfae6 100644 (file)
@@ -194,12 +194,12 @@ if hash packer.io 2>/dev/null; then
 else
     echo "packer.io command not is available. Installing packer ..."
     # Installs Hashicorp's Packer binary, required for verify & merge packer jobs
-    pushd packer
+    pushd "${WORKSPACE}"
     wget -nv "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip"
     mkdir -p "${WORKSPACE}/bin"
-    unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d ${WORKSPACE}/bin/
+    unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d "${WORKSPACE}/bin/"
     # rename packer to avoid conflict with binary in cracklib
-    mv ${WORKSPACE}/bin/packer "${WORKSPACE}/bin/packer.io"
+    mv "${WORKSPACE}/bin/packer" "${WORKSPACE}/bin/packer.io"
     popd
 fi
 
@@ -226,17 +226,25 @@ mkdir -p "$PACKER_LOGS_DIR"
 export PATH="${WORKSPACE}/bin:$PATH"
 
 cd packer
-varfiles=(../packer/vars/*.json)
-templates=(../packer/templates/*.json)
+varfiles=(vars/*.json common-packer/vars/*.json)
+templates=(templates/*.json)
 
 for varfile in "${varfiles[@]}"; do
+    # cloud-env.json is a file containing credentials which is pulled in via
+    # CLOUDENV variable so skip it here.
+    if [[ "$varfile" == *"cloud-env.json"* ]]; then
+        continue
+    fi
+
+    echo "-----> Testing varfile: $varfile"
     for template in "${templates[@]}"; do
-        export PACKER_LOG="yes" && \
-        export PACKER_LOG_PATH="$PACKER_LOGS_DIR/packer-validate-${varfile##*/}-${template##*/}.log" && \
-                    packer.io validate -var-file="$CLOUDENV" \
-                    -var-file="$varfile" "$template"
-        if [ $? -ne 0 ]; then
-            break
+        export PACKER_LOG="yes"
+        export PACKER_LOG_PATH="$PACKER_LOGS_DIR/packer-validate-${varfile##*/}-${template##*/}.log"
+        if output=$(packer.io validate -var-file="$CLOUDENV" -var-file="$varfile" "$template"); then
+            echo "$template: $output"
+        else
+            echo "$template: $output"
+            exit 1
         fi
     done
 done
@@ -304,12 +312,12 @@ if hash packer.io 2>/dev/null; then
 else
     echo "packer.io command not is available. Installing packer ..."
     # Installs Hashicorp's Packer binary, required for verify & merge packer jobs
-    pushd packer
+    pushd "${WORKSPACE}"
     wget -nv "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip"
     mkdir -p "${WORKSPACE}/bin"
-    unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d ${WORKSPACE}/bin/
+    unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d "${WORKSPACE}/bin/"
     # rename packer to avoid conflict with binary in cracklib
-    mv ${WORKSPACE}/bin/packer "${WORKSPACE}/bin/packer.io"
+    mv "${WORKSPACE}/bin/packer" "${WORKSPACE}/bin/packer.io"
     popd
 fi
 
@@ -337,16 +345,22 @@ PACKER_BUILD_LOG="$PACKER_LOGS_DIR/packer-build.log"
 mkdir -p "$PACKER_LOGS_DIR"
 export PATH="${WORKSPACE}/bin:$PATH"
 
+# Prioritize the project's own version of vars if available
+platform_file="vars/$PACKER_PLATFORM.json"
+if [ -f "$PACKER_PLATFORM" ]; then
+    platform_file="vars/$PACKER_PLATFORM.json"
+fi
+
 cd packer
-export PACKER_LOG="yes" && \
-export PACKER_LOG_PATH="$PACKER_BUILD_LOG" && \
-                 packer.io build -color=false \
-                        -var-file="$CLOUDENV" \
-                        -var-file="../packer/vars/$PACKER_PLATFORM.json" \
-                        "../packer/templates/$PACKER_TEMPLATE.json"
+export PACKER_LOG="yes"
+export PACKER_LOG_PATH="$PACKER_BUILD_LOG"
+packer.io build -color=false \
+    -var-file="$CLOUDENV" \
+    -var-file="$platform_file" \
+    "templates/$PACKER_TEMPLATE.json"
 
 # Retrive the list of cloud providers
-clouds=($(jq -r '.builders[].name' "../packer/templates/$PACKER_TEMPLATE.json"))
+mapfile -t clouds < <(jq -r '.builders[].name' "templates/$PACKER_TEMPLATE.json")
 
 # Split public/private clouds logs
 for cloud in "${clouds[@]}"; do