Skip to content

Commit

Permalink
Add retry if needed in pre command hook
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-gr committed Dec 27, 2024
1 parent 887ed7c commit cc9b79a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -euo pipefail

# needed in some systems where retry is not available
if ! declare -f retry > /dev/null; then
source ../scripts/retry.sh
fi

# Secrets must be redacted
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
PRIVATE_CI_GCS_CREDENTIALS_PATH="kv/ci-shared/platform-ingest/gcp-platform-ingest-ci-service-account"
Expand Down
19 changes: 1 addition & 18 deletions .buildkite/scripts/install_macos_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,7 @@ PLATFORM_TYPE_LOWERCASE=$(uname | tr '[:upper:]' '[:lower:]')

export BIN=${WORKSPACE:-$PWD}/bin

retry() {
local retries=$1
shift
local count=0
until "$@"; do
exit=$?
wait=$((2 ** count))
count=$((count + 1))
if [ $count -lt "$retries" ]; then
>&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
sleep $wait
else
>&2 echo "Retry $count/$retries exited $exit, no more retries left."
return $exit
fi
done
return 0
}
source ./retry.sh

create_workspace() {
if [[ ! -d "${BIN}" ]]; then
Expand Down
22 changes: 22 additions & 0 deletions .buildkite/scripts/retry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -euo pipefail

retry() {
local retries=$1
shift
local count=0
until "$@"; do
exit=$?
wait=$((2 ** count))
count=$((count + 1))
if [ $count -lt "$retries" ]; then
>&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
sleep $wait
else
>&2 echo "Retry $count/$retries exited $exit, no more retries left."
return $exit
fi
done
return 0
}

0 comments on commit cc9b79a

Please sign in to comment.