mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 22:26:56 +00:00
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:
committed by
GitHub
parent
d4435d6a11
commit
edce722a68
@@ -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 { }
|
||||
}
|
||||
@@ -27,5 +27,5 @@ Export-ModuleMember -Function @(
|
||||
'Get-WinVersion'
|
||||
'Test-IsWin19'
|
||||
'Test-IsWin16'
|
||||
'Install-Choco'
|
||||
'Choco-Install'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user