diff --git a/ci/utilities/setup_build_environment.sh b/ci/utilities/setup_build_environment.sh index 964a6e4ac..8e4039414 100644 --- a/ci/utilities/setup_build_environment.sh +++ b/ci/utilities/setup_build_environment.sh @@ -75,4 +75,26 @@ if [[ $(uname -s) =~ "MSYS_NT" ]]; then echo 'Converting MSYS Linux-like paths to Windows paths (for Bazel, Python, etc.)' # 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 \ No newline at end of file +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"