Skip to content

Commit

Permalink
Run bazel --version and retry in case of failure (#2152)
Browse files Browse the repository at this point in the history
Fixes #2123
  • Loading branch information
meteorcloudy authored Jan 2, 2025
1 parent 5d2adac commit e8838ad
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions buildkite/bazelci.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,9 @@ def PrepareRepoInCwd(print_cmd_groups, initial_setup=False):

# Dirty workaround for #1660
if initial_setup:
# Run `bazel --version` to make sure Bazel is fetched.
run_bazel_version(bazel_binary)

# Set OUTPUT_BASE environment variable
os.environ["OUTPUT_BASE"] = get_output_base(bazel_binary)

Expand Down Expand Up @@ -1979,6 +1982,18 @@ def rbe_flags(original_flags, accept_cached):
return flags


def run_bazel_version(bazel_binary, max_retry=5):
"""Run `bazel --version` to make sure Bazel is fetched by Bazelisk."""
# Retry to address https://github.com/bazelbuild/continuous-integration/issues/2123
retry = 0
while retry < max_retry:
exit_code = execute_command([bazel_binary, "--version"], fail_if_nonzero=False)
if exit_code == 0:
return
retry += 1
time.sleep(1)


def get_output_base(bazel_binary):
return execute_command_and_get_output(
[bazel_binary] + common_startup_flags() + ["info", "output_base"],
Expand Down

0 comments on commit e8838ad

Please sign in to comment.