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

@@ -175,10 +175,6 @@
"{{ template_dir }}/scripts/Installers/Windows2016/Update-DockerImages.ps1"
]
},
{
"type": "powershell",
"inline": ["choco install vcredist140 -y"]
},
{
"type": "powershell",
"valid_exit_codes": [

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'
)

View File

@@ -3,4 +3,4 @@
## Desc: Install 7zip
################################################################################
choco install 7zip.install -y
Choco-Install -PackageName 7zip.install

View File

@@ -3,7 +3,7 @@
## Desc: Install awscli
################################################################################
choco install awscli -y
Choco-Install -PackageName awscli
$env:PATH =$env:PATH + ";$Env:Programfiles\Amazon\AWSCLIV2"

View File

@@ -3,4 +3,4 @@
## Desc: Install Alibaba Cloud CLI
################################################################################
choco install aliyun-cli -y
Choco-Install -PackageName aliyun-cli

View File

@@ -3,7 +3,7 @@
## Desc: Install Azure CLI
################################################################################
Install-Choco "azure-cli"
Choco-Install -PackageName azure-cli
$AzureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory'
New-Item -ItemType "directory" -Path $AzureCliExtensionPath

View File

@@ -3,6 +3,6 @@
## Desc: Install Bazel and Bazelisk (A user-friendly launcher for Bazel)
################################################################################
choco install bazel -y
Choco-Install -PackageName bazel
npm install -g @bazel/bazelisk

View File

@@ -3,4 +3,4 @@
## Desc: Install Cmake
################################################################################
choco install cmake.install -y --installargs 'ADD_CMAKE_TO_PATH=""System""'
Choco-Install -PackageName cmake.install -ArgumentList "--installargs",'ADD_CMAKE_TO_PATH=""System""'

View File

@@ -13,8 +13,8 @@ Write-Host "Install-Package Docker"
Install-Package -Name docker -ProviderName DockerMsftProvider -Force
Start-Service docker
choco install docker-compose -y
Write-Host "Install-Package Docker-Compose"
Choco-Install -PackageName docker-compose
# Install helm
Write-Host "Install Helm"
choco install kubernetes-helm
Choco-Install -PackageName kubernetes-helm

View File

@@ -3,7 +3,7 @@
## Desc: Install latest stable version of Microsoft Edge browser
################################################################################
choco install microsoft-edge -y
Choco-Install -PackageName microsoft-edge
# Install Microsoft Edge Web Driver
Write-Host "Install Edge WebDriver"

View File

@@ -32,7 +32,7 @@ Install-Exe -Url $downloadUrl `
"/o:BashTerminalOption=ConHost", `
"/COMPONENTS=gitlfs")
choco install hub
Choco-Install -PackageName hub
# Disable GCM machine-wide
[Environment]::SetEnvironmentVariable("GCM_INTERACTIVE", "Never", [System.EnvironmentVariableTarget]::Machine)

View File

@@ -3,4 +3,4 @@
## Desc: Install GitVersion
################################################################################
choco install gitversion.portable -y
Choco-Install -PackageName gitversion.portable

View File

@@ -3,4 +3,4 @@
## Desc: Install Inno Setup
################################################################################
choco install innosetup -y
Choco-Install -PackageName innosetup

View File

@@ -61,9 +61,9 @@ setx JAVA_HOME_11_X64 $latestJava11Install /M
# Install Java tools
# Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK
choco install ant -y -i
choco install maven -y -i --version=3.6.3
choco install gradle -y
Choco-Install -PackageName ant -ArgumentList "-i"
Choco-Install -PackageName maven -ArgumentList "-i", "--version=3.6.3"
Choco-Install -PackageName gradle
# Move maven variables to Machine. They may not be in the environment for this script so we need to read them from the registry.
$userSid = (Get-WmiObject win32_useraccount -Filter "name = '$env:USERNAME' AND domain = '$env:USERDOMAIN'").SID

View File

@@ -3,4 +3,4 @@
## Desc: Install jq
################################################################################
choco install jq -y
Choco-Install -PackageName jq

View File

@@ -3,4 +3,4 @@
## Desc: Install Julia
################################################################################
choco install julia -y --ia "/DIR=C:\Julia"
Choco-Install -PackageName julia -ArgumentList "--ia","/DIR=C:\Julia"

View File

@@ -3,4 +3,4 @@
## Desc: Install KubernetesCli
################################################################################
choco install kubernetes-cli -y
Choco-Install -PackageName kubernetes-cli

View File

@@ -3,7 +3,7 @@
## Desc: Install Mercurial
################################################################################
choco install hg -y --version 5.0.0
Choco-Install -PackageName hg -ArgumentList "--version", "5.0.0"
$hgPath = "${env:ProgramFiles}\Mercurial\"
Add-MachinePathItem $hgPath

View File

@@ -5,7 +5,7 @@
Import-Module -Name ImageHelpers -Force
Install-Choco "mingw"
Choco-Install -PackageName mingw
# Make a copy of mingw32-make.exe to make.exe, which is a more discoverable name
# and so the same command line can be used on Windows as on macOS and Linux

View File

@@ -3,7 +3,7 @@
## Desc: Install NSIS
################################################################################
choco install nsis -y
Choco-Install -PackageName nsis
$NsisPath = "${env:ProgramFiles(x86)}\NSIS\"
Add-MachinePathItem $NsisPath

View File

@@ -12,7 +12,7 @@ $CachePath = 'C:\npm\cache'
New-Item -Path $PrefixPath -Force -ItemType Directory
New-Item -Path $CachePath -Force -ItemType Directory
choco install nodejs-lts -y --force
Choco-Install -PackageName nodejs-lts -ArgumentList "--force"
Add-MachinePathItem $PrefixPath
$env:Path = Get-MachinePath

View File

@@ -3,4 +3,4 @@
## Desc: Install OpenSSL
################################################################################
choco install openssl.light -y
Choco-Install -PackageName openssl.light

View File

@@ -8,10 +8,10 @@ Import-Module -Name ImageHelpers
# Install latest PHP in chocolatey
$installDir = "c:\tools\php"
choco install php -y --force --params "/InstallDir:$installDir"
Choco-Install -PackageName php -ArgumentList "--force", "--params", "/InstallDir:$installDir"
# Install latest Composer in chocolatey
choco install composer --ia "/DEV=$installDir /PHP=$installDir"
Choco-Install -PackageName composer -ArgumentList "--ia", "/DEV=$installDir /PHP=$installDir"
# update path to extensions and enable curl and mbstring extensions, and enable php openssl extensions.
((Get-Content -path $installDir\php.ini -Raw) -replace ';extension=curl','extension=curl' -replace ';extension=mbstring','extension=mbstring' -replace ';extension_dir = "ext"','extension_dir = "ext"' -replace 'extension=";php_openssl.dll"','extension_dir = "php_openssl.dll"') | Set-Content -Path $installDir\php.ini

View File

@@ -3,4 +3,4 @@
## Desc: Install Packer
################################################################################
choco install packer -y
Choco-Install -PackageName packer

View File

@@ -3,4 +3,4 @@
## Desc: Install Perl
################################################################################
choco install strawberryperl -y
Choco-Install -PackageName strawberryperl

View File

@@ -8,7 +8,7 @@ Import-Module -Name ImageHelpers
# Install the latest version of sbt.
# See https://chocolatey.org/packages/sbt
choco install sbt -y
Choco-Install -PackageName sbt
$env:SBT_HOME="${env:ProgramFiles(x86)}\sbt"

View File

@@ -3,4 +3,4 @@
## Desc: Install Subversion
################################################################################
choco install svn -y
Choco-Install -PackageName svn

View File

@@ -3,4 +3,4 @@
## Desc: Install latest stable version of VSWhere
################################################################################
choco install vswhere -y
Choco-Install -PackageName vswhere

View File

@@ -3,9 +3,9 @@
## Desc: Install WIX.
################################################################################
Import-Module -Name ImageHelpers -Force;
Import-Module -Name ImageHelpers -Force
choco install wixtoolset -y --force
Choco-Install -PackageName wixtoolset -ArgumentList "--force"
if(Test-IsWin19)
{

View File

@@ -3,4 +3,4 @@
## Desc: Install zstd
################################################################################
choco install zstandard -y
Choco-Install -PackageName zstandard

View File

@@ -111,7 +111,10 @@ choco feature enable -n allowGlobalConfirmation
Remove-Item -Path $env:ChocolateyInstall\bin\cpack.exe -Force
# Install webpi
choco install webpicmd -y
Choco-Install -PackageName webpicmd
# Install vcredist140
Choco-Install -PackageName vcredist140
# Expand disk size of OS drive

View File

@@ -109,7 +109,7 @@ choco feature enable -n allowGlobalConfirmation
Remove-Item -Path $env:ChocolateyInstall\bin\cpack.exe -Force
# Install webpi
choco install webpicmd -y
Choco-Install -PackageName webpicmd
# Expand disk size of OS drive