Files
sunnypilot/scripts/retry.sh
Justin Newberry 12da944f1c jenkins: retry build_devel (#30628)
* will it work

* retry build devel

* correct p[ath

* try a failure

* Revert "try a failure"

This reverts commit ba4e6a0a2096b94887fcfbf7d011e34aa2a16c41.
old-commit-hash: 36bebb1aa0
2023-12-06 17:22:32 -08:00

28 lines
503 B
Bash
Executable File

#!/bin/bash
function fail {
echo $1 >&2
exit 1
}
function retry {
local n=1
local max=3 # 3 retries before failure
local delay=5 # delay between retries, 5 seconds
while true; do
echo "Running command '$@' with retry, attempt $n/$max"
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
sleep $delay;
else
fail "The command has failed after $n attempts."
fi
}
done
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
retry "$@"
fi