Skip to content

Commit 1f0939d

Browse files
author
Ola Buildkite
committed
Add retry logic for binary download
1 parent a0c7ae2 commit 1f0939d

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ steps:
305305
trigger: "deploy-foo-service"
306306
```
307307

308+
### Download Retry Behavior
309+
310+
The plugin automatically retries binary downloads up to 3 times with a 5-second delay between attempts. This handles transient network issues when downloading from GitHub.
311+
308312
### `hooks` (optional)
309313

310314
Currently supports a list of `commands` you wish to execute after the `watched` pipelines have been triggered

hooks/command

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
# Retry configuration for downloads
5+
# Hardcoded values - meant for transient network issues, not hard outages
6+
max_retries=3
7+
retry_delay=5
8+
49
executable="monorepo-diff-buildkite-plugin"
510
executable_version_file="${executable}.version"
611

@@ -66,6 +71,29 @@ downloader() {
6671
fi
6772
}
6873

74+
# Retry wrapper for downloads (SUP-5615)
75+
download_with_retry() {
76+
local _url="$1"
77+
local _dest="$2"
78+
local _attempt=1
79+
80+
while [ $_attempt -le "$max_retries" ]; do
81+
say "Downloading binary (attempt ${_attempt}/${max_retries})..."
82+
if downloader "$_url" "$_dest"; then
83+
say "Download successful"
84+
return 0
85+
fi
86+
87+
if [ $_attempt -lt "$max_retries" ]; then
88+
say "Download failed, retrying in ${retry_delay} seconds..."
89+
sleep "$retry_delay"
90+
fi
91+
_attempt=$((_attempt + 1))
92+
done
93+
94+
return 1
95+
}
96+
6997
get_latest_version() {
7098
local _repo="https://api.github.com/repos/buildkite-plugins/monorepo-diff-buildkite-plugin"
7199
local _version=""
@@ -143,14 +171,14 @@ download_binary_and_run() {
143171
fi
144172

145173
if [ -n "${_url}" ]; then
146-
if ! downloader "$_url" "${executable}"; then
147-
say "failed to download $_url"
174+
# Use retry wrapper for resilient downloads (SUP-5615)
175+
if ! download_with_retry "$_url" "${executable}"; then
176+
say "Failed to download $_url after ${max_retries} attempts"
148177
exit 1
149178
fi
150179
echo "${_binary_version}" > "${executable_version_file}"
151180
fi
152181

153-
# todo: move it to a more secure place
154182
chmod +x "${executable}"
155183

156184
./"${executable}"

0 commit comments

Comments
 (0)