diff --git a/scripts/ops/hermes_demo_lib.sh b/scripts/ops/hermes_demo_lib.sh index df42864d7..468a3dfde 100644 --- a/scripts/ops/hermes_demo_lib.sh +++ b/scripts/ops/hermes_demo_lib.sh @@ -67,11 +67,17 @@ last_build_number() { python3 -c 'import json,sys; print(json.load(sys.stdin)["lastBuild"]["number"])' } -wait_for_build() { # job number [tries] -> prints result - local job="$1" num="$2" tries="${3:-120}" - for _ in $(seq 1 "$tries"); do - sleep 10 - local body result building +# Polls before sleeping, not after. Sleeping first meant a build that had +# already finished still cost a full interval of silence, which on stage reads +# as the script having missed it. The interval is short for the same reason: +# the wait is dead air in front of an audience, and a Jenkins status read is +# cheap. +BUILD_POLL_SECONDS="${BUILD_POLL_SECONDS:-3}" + +wait_for_build() { # job number [max_seconds] -> prints result + local job="$1" num="$2" budget="${3:-1500}" + local waited=0 body building result + while [ "$waited" -le "$budget" ]; do body="$(jenkins_get "/job/$job/$num/api/json?tree=result,building" || true)" building="$(printf '%s' "$body" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("building"))' 2>/dev/null || echo unknown)" @@ -80,6 +86,8 @@ wait_for_build() { # job number [tries] -> prints result printf '%s' "$result" return 0 fi + sleep "$BUILD_POLL_SECONDS" + waited=$((waited + BUILD_POLL_SECONDS)) done printf 'TIMEOUT' }