Improve choco stability by adding retry logic on Windows images (#721)

Add retry logic for choco install to avoid random failures
This commit is contained in:
Aleksandr Chebotov
2020-04-17 10:53:30 +03:00
committed by GitHub
parent d4435d6a11
commit edce722a68
33 changed files with 57 additions and 59 deletions

View File

@@ -1,33 +1,32 @@
function Install-Choco {
function Choco-Install {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$install,
[int]$retries = 5
[string] $PackageName,
[string[]] $ArgumentList,
[int] $RetryCount = 5
)
begin { }
process {
$condition = $false
$count = 0
do {
Write-Output "running: powershell choco install $install -y"
powershell choco install $install -y
$count = 1
while($true)
{
Write-Host "Running [#$count]: choco install $packageName -y $argumentList"
choco install $packageName -y @argumentList
$installed = powershell choco list -lo $install --all
$match = (($installed -match "^$install.*").Length -ne 0)
if ($match) {
Write-Output "package installed: $install"
$condition = $true
$pkg = choco list --localonly $packageName --exact --all --limitoutput
if ($pkg) {
Write-Host "Package installed: $pkg"
break
}
else {
$count++
if ($count -eq $retries) {
Write-Error "Could not install $install after $count attempts"
if ($count -ge $retryCount) {
Write-Host "Could not install $packageName after $count attempts"
exit 1
}
Start-Sleep -Seconds 30
}
} while ($condition -eq $false)
}
}
end { }
}

View File

@@ -27,5 +27,5 @@ Export-ModuleMember -Function @(
'Get-WinVersion'
'Test-IsWin19'
'Test-IsWin16'
'Install-Choco'
'Choco-Install'
)