Created
August 17, 2015 12:55
-
-
Save igorpopovio/5398f9f5a9926cd36dd9 to your computer and use it in GitHub Desktop.
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
function Main() { | |
RetryCommand ` | |
-maxRetries 5 ` | |
-delayInSeconds 0 ` | |
-command { cmd /c $SIGNTOOL sign /v /debug /sm /t $TIMESTAMP_URL $files } | |
RetryCommand ` | |
-maxRetries 5 ` | |
-delayInSeconds 3 ` | |
-command { . $INSTALLSHIELD $arguments } | |
} | |
function RetryCommand($maxRetries, $delayInSeconds, $command) { | |
$textCommand = $ExecutionContext.InvokeCommand.ExpandString($command) | |
LogImportant "Calling `n`t $textCommand" | |
$failedTimes = 0 | |
do { | |
& $command | |
$commandExitCode = $lastExitCode | |
$successful = $commandExitCode -eq 0 | |
if (-not $successful) { $failedTimes++ } | |
$shouldRetry = -not $successful -and $failedTimes -le $maxRetries | |
if ($shouldRetry) { | |
$retriesLeft = $maxRetries - $failedTimes + 1 | |
LogImportant "FAILED!!! Command: $textCommand" | |
LogImportant "We'll retry again after $delayInSeconds seconds ($retriesLeft/$maxRetries retries left)..." | |
Start-Sleep -Seconds $delayInSeconds | |
} | |
} while ($shouldRetry) | |
if (-not $successful) { Write-Error "FAILED!!! Command: $textCommand (exit code = $commandExitCode)" } | |
} | |
Main |
Other stuff: only $lastExitCode
works in this case. $?
won't work!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stuff to note: forcing string interpolation (variable substitution):