Files
runner-images/images/win/scripts/ImageHelpers/ChocoHelpers.ps1
Aleksandr Chebotov edce722a68 Improve choco stability by adding retry logic on Windows images (#721)
Add retry logic for choco install to avoid random failures
2020-04-17 10:53:30 +03:00

32 lines
919 B
PowerShell

function Choco-Install {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string] $PackageName,
[string[]] $ArgumentList,
[int] $RetryCount = 5
)
process {
$count = 1
while($true)
{
Write-Host "Running [#$count]: choco install $packageName -y $argumentList"
choco install $packageName -y @argumentList
$pkg = choco list --localonly $packageName --exact --all --limitoutput
if ($pkg) {
Write-Host "Package installed: $pkg"
break
}
else {
$count++
if ($count -ge $retryCount) {
Write-Host "Could not install $packageName after $count attempts"
exit 1
}
Start-Sleep -Seconds 30
}
}
}
}