X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fpacker-build.sh;h=3349a723374af0c7f5f7d3c1115b4a1c5e08e592;hb=eccb60c2014c1dfed187ad0d783a57664fac3086;hp=0d9d68d5243d174c77a28466e32d0494ebe4bcfc;hpb=58776ad5961580fcdc1cc56a9309e9da52e7673c;p=releng%2Fglobal-jjb.git diff --git a/shell/packer-build.sh b/shell/packer-build.sh index 0d9d68d5..3349a723 100644 --- a/shell/packer-build.sh +++ b/shell/packer-build.sh @@ -36,6 +36,32 @@ packer.io validate \ -var-file="$CLOUDENV" \ -var-file="$platform_file" \ "templates/$PACKER_TEMPLATE.json" + +set -x +# If this is a Gerrit system, check patch comments for successful verify build. +if [[ -n ${GERRIT_URL:-} ]] && \ + [[ -n ${GERRIT_CHANGE_NUMBER:-} ]] && \ + [[ -n ${GERRIT_PATCHSET_NUMBER:-} ]] && \ + curl -s "${GERRIT_URL}/changes/${GERRIT_CHANGE_NUMBER}/detail" \ + | tail -n +2 | jq .messages[].message? \ + | grep "Patch Set ${GERRIT_PATCHSET_NUMBER}:.*Build Successful.*verify-build-${PACKER_PLATFORM}-${PACKER_TEMPLATE}" +then + echo "Build already successful for this patch set. Skipping merge build..." + exit +# If this is Github, check the last non-merge commit for a successful Packer +# Verify Build status. +elif [[ "${GIT_BASE:-}" =~ https://github.com ]]; then + LAST_CHANGE_SHA=$(git log --no-merges -1 --format=%H) + API_BASE=$(echo "$GIT_BASE" | sed -E 's#(www.)?github.com#api.github.com/repos#') + STATUS=$(curl "${API_BASE}/statuses/${LAST_CHANGE_SHA}" \ + | jq ".[] | select(.state == \"success\" and .context == \"Packer ${PACKER_PLATFORM}-${PACKER_TEMPLATE} Verify Build\")") + if [[ -n ${STATUS} ]]; then + echo "Build already successful for this patch set. Skipping merge build..." + exit + fi +fi +set +x + packer.io build -color=false \ -var-file="$CLOUDENV" \ -var-file="$platform_file" \