Fix API breakage caused by OS Plugin version scan
[releng/global-jjb.git] / shell / packer-validate.sh
index e19c973..61e1431 100644 (file)
@@ -21,18 +21,26 @@ mkdir -p "$PACKER_LOGS_DIR"
 export PATH="${WORKSPACE}/bin:$PATH"
 
 cd packer
-varfiles=(../packer/vars/*)
-templates=(../packer/templates/*)
+varfiles=(vars/*.json common-packer/vars/*.json)
+templates=(templates/*.json)
 
 for varfile in "${varfiles[@]}"; do
-    [[ "${varfile##*/}" =~ ^(cloud-env.*)$ ]] && continue
+    # cloud-env.json is a file containing credentials which is pulled in via
+    # CLOUDENV variable so skip it here. Also handle the case where a project
+    # has not vars/*.json file.
+    if [[ "$varfile" == *"cloud-env.json"* ]] || [[ "$varfile" == 'vars/*.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