2019-05-24 08:14:37 +03:00
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory, ValueFromPipeline)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[ScriptBlock] $ScriptBlock,
|
|
|
|
[Int] $RetryCount = 3
|
|
|
|
)
|
|
|
|
|
|
|
|
Process {
|
|
|
|
$Attempt = 0
|
|
|
|
While ($Attempt -lt $RetryCount) {
|
|
|
|
try {
|
|
|
|
Invoke-Command -ScriptBlock $ScriptBlock
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
throw "Script failed to execute."
|
|
|
|
} catch {
|
|
|
|
$Attempt = $Attempt + 1
|
|
|
|
if ($Attempt -lt $RetryCount) {
|
2019-05-24 18:11:47 +03:00
|
|
|
Write-Host "##vso[task.logissue type=warning] ($Attempt of $RetryCount) Script failed to execute, retrying..."
|
2019-05-24 08:14:37 +03:00
|
|
|
} else {
|
2019-05-24 18:11:47 +03:00
|
|
|
Write-Host "##vso[task.logissue type=warning] ($Attempt of $RetryCount) Script failed to execute."
|
2019-05-24 08:14:37 +03:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|