Add a retry logic to avoid flakes when downloading Bazel

PiperOrigin-RevId: 720349541
This commit is contained in:
Nitin Srinivasan 2025-01-27 16:35:17 -08:00 committed by jax authors
parent 4fe937683e
commit 36679d89e3

View File

@ -76,3 +76,25 @@ if [[ $(uname -s) =~ "MSYS_NT" ]]; then
# Convert all "JAXCI.*DIR" variables
source <(python3 ./ci/utilities/convert_msys_paths_to_win_paths.py --convert $(env | grep "JAXCI.*DIR" | awk -F= '{print $1}'))
fi
function retry {
local cmd="$1"
local max_attempts=3
local attempt=1
local delay=10
while [[ $attempt -le $max_attempts ]] ; do
if eval "$cmd"; then
return 0
fi
echo "Attempt $attempt failed. Retrying in $delay seconds..."
sleep $delay # Prevent overloading
attempt=$((attempt + 1))
done
echo "$cmd failed after $max_attempts attempts."
exit 1
}
# Retry "bazel --version" 3 times to avoid flakiness when downloading bazel.
retry "bazel --version"