Skip to content

Commit b169fdf

Browse files
committed
Add function to retry a command
1 parent 1138083 commit b169fdf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/ci/circle/script

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ clean_node() {
165165
return 0
166166
}
167167

168+
# Retries a command a maximum number of times.
169+
#
170+
# $1 - number of retries
171+
# $2 - command to retry
172+
retry() {
173+
local code
174+
for i in $(seq 1 "$1"); do
175+
# By way of operator precedence, the clause after `||` only gets executed if one of the prior commands fails...
176+
"$2" && code=0 && break || code="$?" && sleep 15;
177+
done
178+
return "${code}"
179+
}
180+
168181
# Performs install tasks.
169182
#
170183
# $1 - log file

0 commit comments

Comments
 (0)