X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fpacker-build.sh;h=b015271c45756154e08c50bc06a086a8548fc7ce;hb=e1a8dc64cfe10360ebdcadd28806adf800760ce7;hp=e730545d81e54b6c27c6f22439b16973c148209f;hpb=bb5e0da850b1c5ed31cf76af62d91b506c13d8dd;p=releng%2Fglobal-jjb.git diff --git a/shell/packer-build.sh b/shell/packer-build.sh index e730545d..b015271c 100644 --- a/shell/packer-build.sh +++ b/shell/packer-build.sh @@ -23,15 +23,41 @@ mkdir -p "$PACKER_LOGS_DIR" export PATH="${WORKSPACE}/bin:$PATH" 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" + +# Prioritize the project's own version of vars if available +platform_file="common-packer/vars/$PACKER_PLATFORM.json" +if [[ -f "vars/$PACKER_PLATFORM.json" ]]; then + platform_file="vars/$PACKER_PLATFORM.json" +fi + +export PACKER_LOG="yes" +export PACKER_LOG_PATH="$PACKER_BUILD_LOG" +packer.io validate \ + -var-file="$CLOUDENV" \ + -var-file="$platform_file" \ + "templates/$PACKER_TEMPLATE.json" +packer.io build -color=false \ + -var-file="$CLOUDENV" \ + -var-file="$platform_file" \ + "templates/$PACKER_TEMPLATE.json" + +# Extract image name from log and store value in the downstream job +if [[ ${UPDATE_CLOUD_IMAGE} ]]; then + + NEW_IMAGE_NAME=$(grep -P '(\s+.*image: )(ZZCI\s+.*\d+-\d+\.\d+)' \ + "$PACKER_BUILD_LOG" | awk -F': ' '{print $4}') + + echo NEW_IMAGE_NAME="$NEW_IMAGE_NAME" >> "$WORKSPACE/variables.prop" + echo "NEW_IMAGE_NAME: ${NEW_IMAGE_NAME}" + + # Copy variables.prop to variables.jenkins-trigger so that the end of build + # trigger can pick up the file as input for triggering downstream jobs. + # Dont tigger downstream job when UPDATE_CLOUD_IMAGE is set to 'false' + cp $WORKSPACE/variables.prop $WORKSPACE/variables.jenkins-trigger +fi # Retrive the list of cloud providers -mapfile -t 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