#!/usr/bin/env bash # Watch BuildBot until a build NEWER than $1 completes. Usage: watch-buildbot.sh [prev_number] [timeout_s] set -euo pipefail BB=${BB:-http://192.168.3.110:8010} PREV=${1:-0} TIMEOUT=${2:-420} API="$BB/api/v2/builds?order=-number&limit=1" latest() { curl -sf -m 8 "$API" | python3 -c 'import json,sys d=json.load(sys.stdin); b=d["builds"][0] print(b["number"], b.get("state","-"), b.get("complete",False))'; } for i in $(seq 1 $((TIMEOUT / 10))); do read -r NUM STATE COMPLETE <<< "$(latest || echo '- - -')" if [ "${NUM:-0}" -gt "$PREV" ] 2>/dev/null && [ "$COMPLETE" = "True" ]; then RESULT=$(curl -sf -m 8 "$BB/api/v2/builds/$NUM" | python3 -c 'import json,sys b=json.load(sys.stdin)["builds"][0]; print(b.get("results"))') echo "build=$NUM state=$STATE results=$RESULT elapsed=$((i * 10))s" if [ "$RESULT" = "0" ]; then exit 0; else exit 1; fi fi sleep 10 done echo "TIMEOUT waiting for build > $PREV" exit 2