Don't try to pushd into dir that doesn't exist
[releng/global-jjb.git] / .jjb-test / expected-xml / github-ciman-packer-merge-centos-java-builder
index 89f55ac..2d3a91e 100644 (file)
@@ -71,7 +71,7 @@ For example '<1.0.0' or '>=1.0.0,<2.0.0'.
         <hudson.model.StringParameterDefinition>
           <name>PACKER_VERSION</name>
           <description>Packer version to download and install.</description>
-          <defaultValue>1.1.1</defaultValue>
+          <defaultValue>1.1.3</defaultValue>
         </hudson.model.StringParameterDefinition>
       </parameterDefinitions>
     </hudson.model.ParametersDefinitionProperty>
@@ -163,7 +163,7 @@ zxiiro</whitelist>
     </org.jenkinsci.plugins.configfiles.builder.ConfigFileBuildStep>
     <EnvInjectBuilder>
       <info>
-        <propertiesContent>PACKER_VERSION=1.1.1
+        <propertiesContent>PACKER_VERSION=1.1.3
 </propertiesContent>
       </info>
     </EnvInjectBuilder>
@@ -184,7 +184,7 @@ echo &quot;---&gt; packer-install.sh&quot;
 
 # $PACKER_VERSION        : Define a packer version passed as job paramter
 
-PACKER_VERSION=&quot;${PACKER_VERSION:-1.0.2}&quot;
+PACKER_VERSION=&quot;${PACKER_VERSION:-1.1.3}&quot;
 
 # Ensure we fail the job if any steps fail.
 set -eu -o pipefail
@@ -194,12 +194,12 @@ if hash packer.io 2&gt;/dev/null; then
 else
     echo &quot;packer.io command not is available. Installing packer ...&quot;
     # Installs Hashicorp's Packer binary, required for verify &amp; merge packer jobs
-    pushd packer
+    pushd &quot;${WORKSPACE}&quot;
     wget -nv &quot;https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip&quot;
     mkdir -p &quot;${WORKSPACE}/bin&quot;
-    unzip &quot;packer_${PACKER_VERSION}_linux_amd64.zip&quot; -d ${WORKSPACE}/bin/
+    unzip &quot;packer_${PACKER_VERSION}_linux_amd64.zip&quot; -d &quot;${WORKSPACE}/bin/&quot;
     # rename packer to avoid conflict with binary in cracklib
-    mv ${WORKSPACE}/bin/packer &quot;${WORKSPACE}/bin/packer.io&quot;
+    mv &quot;${WORKSPACE}/bin/packer&quot; &quot;${WORKSPACE}/bin/packer.io&quot;
     popd
 fi
 
@@ -226,17 +226,25 @@ mkdir -p &quot;$PACKER_LOGS_DIR&quot;
 export PATH=&quot;${WORKSPACE}/bin:$PATH&quot;
 
 cd packer
-varfiles=(../packer/vars/*.json)
-templates=(../packer/templates/*.json)
+varfiles=(vars/*.json common-packer/vars/*.json)
+templates=(templates/*.json)
 
 for varfile in &quot;${varfiles[@]}&quot;; do
+    # cloud-env.json is a file containing credentials which is pulled in via
+    # CLOUDENV variable so skip it here.
+    if [[ &quot;$varfile&quot; == *&quot;cloud-env.json&quot;* ]]; then
+        continue
+    fi
+
+    echo &quot;-----&gt; Testing varfile: $varfile&quot;
     for template in &quot;${templates[@]}&quot;; do
-        export PACKER_LOG=&quot;yes&quot; &amp;&amp; \
-        export PACKER_LOG_PATH=&quot;$PACKER_LOGS_DIR/packer-validate-${varfile##*/}-${template##*/}.log&quot; &amp;&amp; \
-                    packer.io validate -var-file=&quot;$CLOUDENV&quot; \
-                    -var-file=&quot;$varfile&quot; &quot;$template&quot;
-        if [ $? -ne 0 ]; then
-            break
+        export PACKER_LOG=&quot;yes&quot;
+        export PACKER_LOG_PATH=&quot;$PACKER_LOGS_DIR/packer-validate-${varfile##*/}-${template##*/}.log&quot;
+        if output=$(packer.io validate -var-file=&quot;$CLOUDENV&quot; -var-file=&quot;$varfile&quot; &quot;$template&quot;); then
+            echo &quot;$template: $output&quot;
+        else
+            echo &quot;$template: $output&quot;
+            exit 1
         fi
     done
 done
@@ -273,7 +281,7 @@ exit 0
       <info>
         <propertiesContent>PACKER_PLATFORM=centos
 PACKER_TEMPLATE=java-builder
-PACKER_VERSION=1.1.1
+PACKER_VERSION=1.1.3
 </propertiesContent>
       </info>
     </EnvInjectBuilder>
@@ -294,7 +302,7 @@ echo &quot;---&gt; packer-install.sh&quot;
 
 # $PACKER_VERSION        : Define a packer version passed as job paramter
 
-PACKER_VERSION=&quot;${PACKER_VERSION:-1.0.2}&quot;
+PACKER_VERSION=&quot;${PACKER_VERSION:-1.1.3}&quot;
 
 # Ensure we fail the job if any steps fail.
 set -eu -o pipefail
@@ -304,12 +312,12 @@ if hash packer.io 2&gt;/dev/null; then
 else
     echo &quot;packer.io command not is available. Installing packer ...&quot;
     # Installs Hashicorp's Packer binary, required for verify &amp; merge packer jobs
-    pushd packer
+    pushd &quot;${WORKSPACE}&quot;
     wget -nv &quot;https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip&quot;
     mkdir -p &quot;${WORKSPACE}/bin&quot;
-    unzip &quot;packer_${PACKER_VERSION}_linux_amd64.zip&quot; -d ${WORKSPACE}/bin/
+    unzip &quot;packer_${PACKER_VERSION}_linux_amd64.zip&quot; -d &quot;${WORKSPACE}/bin/&quot;
     # rename packer to avoid conflict with binary in cracklib
-    mv ${WORKSPACE}/bin/packer &quot;${WORKSPACE}/bin/packer.io&quot;
+    mv &quot;${WORKSPACE}/bin/packer&quot; &quot;${WORKSPACE}/bin/packer.io&quot;
     popd
 fi
 
@@ -337,16 +345,22 @@ PACKER_BUILD_LOG=&quot;$PACKER_LOGS_DIR/packer-build.log&quot;
 mkdir -p &quot;$PACKER_LOGS_DIR&quot;
 export PATH=&quot;${WORKSPACE}/bin:$PATH&quot;
 
+# Prioritize the project's own version of vars if available
+platform_file=&quot;vars/$PACKER_PLATFORM.json&quot;
+if [ -f &quot;$PACKER_PLATFORM&quot; ]; then
+    platform_file=&quot;vars/$PACKER_PLATFORM.json&quot;
+fi
+
 cd packer
-export PACKER_LOG=&quot;yes&quot; &amp;&amp; \
-export PACKER_LOG_PATH=&quot;$PACKER_BUILD_LOG&quot; &amp;&amp; \
-                 packer.io build -color=false \
-                        -var-file=&quot;$CLOUDENV&quot; \
-                        -var-file=&quot;../packer/vars/$PACKER_PLATFORM.json&quot; \
-                        &quot;../packer/templates/$PACKER_TEMPLATE.json&quot;
+export PACKER_LOG=&quot;yes&quot;
+export PACKER_LOG_PATH=&quot;$PACKER_BUILD_LOG&quot;
+packer.io build -color=false \
+    -var-file=&quot;$CLOUDENV&quot; \
+    -var-file=&quot;$platform_file&quot; \
+    &quot;templates/$PACKER_TEMPLATE.json&quot;
 
 # Retrive the list of cloud providers
-clouds=($(jq -r '.builders[].name' &quot;../packer/templates/$PACKER_TEMPLATE.json&quot;))
+mapfile -t clouds &lt; &lt;(jq -r '.builders[].name' &quot;templates/$PACKER_TEMPLATE.json&quot;)
 
 # Split public/private clouds logs
 for cloud in &quot;${clouds[@]}&quot;; do