-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This script will retry a given command n times (by default we use 5). | ||
# Currently we use this to retry `git clone` during official builds. | ||
|
||
param ( | ||
[Parameter(Mandatory=$true)][string]$command, | ||
[int]$retries = "5" | ||
) | ||
|
||
$done = $false | ||
[int]$retryCount = "0" | ||
|
||
do { | ||
Invoke-Expression $command | ||
if ("$LASTEXITCODE" -ne 0) { | ||
$retryCount = $retryCount + 1 | ||
} else { | ||
$done = $true | ||
} | ||
if ($retryCount -ge $retries){ | ||
Write-Host "Could not complete command after $retries attempts" | ||
$done = $true | ||
} | ||
} | ||
While ($done -eq $false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
# Set default value for __retries | ||
__retries=5 | ||
__command= | ||
|
||
while :; do | ||
if [ $# -le 0 ]; then | ||
break | ||
fi | ||
|
||
lowerI="$(echo $1 | awk '{print tolower($0)}')" | ||
case $lowerI in | ||
command|-command) | ||
if [ -n "$2" ]; then | ||
__command="$2" | ||
shift | ||
else | ||
echo "ERROR: 'command' requires a non-empty option argument" | ||
exit 1 | ||
fi | ||
;; | ||
retries|-retries) | ||
if [ -n "$2" ]; then | ||
__retries="$2" | ||
shift | ||
else | ||
echo "ERROR: 'retries' requires a non-empty option argument" | ||
exit 1 | ||
fi | ||
;; | ||
*) | ||
esac | ||
|
||
shift | ||
done | ||
|
||
if [[ -z "$__command"]] | ||
echo "ERROR: Please supply a value for '-command'" | ||
exit 2 | ||
fi | ||
|
||
__retryCount=0 | ||
until $exit_code -eq 0 || [ $__retryCount -ge $__retries ]; do | ||
eval $__command | ||
exit_code=$? | ||
(__retryCount++) | ||
echo "Failed to execute command, retrying" | ||
done | ||
|
||
exit $exit_code |