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" "{{ template_dir }}/scripts/Installers/Windows2016/Update-DockerImages.ps1"
] ]
}, },
{
"type": "powershell",
"inline": ["choco install vcredist140 -y"]
},
{ {
"type": "powershell", "type": "powershell",
"valid_exit_codes": [ "valid_exit_codes": [

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,4 +3,4 @@
## Desc: Install Alibaba Cloud CLI ## 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 ## Desc: Install Azure CLI
################################################################################ ################################################################################
Install-Choco "azure-cli" Choco-Install -PackageName azure-cli
$AzureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory' $AzureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory'
New-Item -ItemType "directory" -Path $AzureCliExtensionPath New-Item -ItemType "directory" -Path $AzureCliExtensionPath

View File

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

View File

@@ -3,4 +3,4 @@
## Desc: Install Cmake ## 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 Install-Package -Name docker -ProviderName DockerMsftProvider -Force
Start-Service docker 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" 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 ## Desc: Install latest stable version of Microsoft Edge browser
################################################################################ ################################################################################
choco install microsoft-edge -y Choco-Install -PackageName microsoft-edge
# Install Microsoft Edge Web Driver # Install Microsoft Edge Web Driver
Write-Host "Install Edge WebDriver" Write-Host "Install Edge WebDriver"

View File

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

View File

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

View File

@@ -3,4 +3,4 @@
## Desc: Install Inno Setup ## 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 # Install Java tools
# Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK # Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK
choco install ant -y -i Choco-Install -PackageName ant -ArgumentList "-i"
choco install maven -y -i --version=3.6.3 Choco-Install -PackageName maven -ArgumentList "-i", "--version=3.6.3"
choco install gradle -y 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. # 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 $userSid = (Get-WmiObject win32_useraccount -Filter "name = '$env:USERNAME' AND domain = '$env:USERDOMAIN'").SID

View File

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

View File

@@ -3,4 +3,4 @@
## Desc: Install Julia ## 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 ## Desc: Install KubernetesCli
################################################################################ ################################################################################
choco install kubernetes-cli -y Choco-Install -PackageName kubernetes-cli

View File

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

View File

@@ -5,7 +5,7 @@
Import-Module -Name ImageHelpers -Force 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 # 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 # 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 ## Desc: Install NSIS
################################################################################ ################################################################################
choco install nsis -y Choco-Install -PackageName nsis
$NsisPath = "${env:ProgramFiles(x86)}\NSIS\" $NsisPath = "${env:ProgramFiles(x86)}\NSIS\"
Add-MachinePathItem $NsisPath Add-MachinePathItem $NsisPath

View File

@@ -12,7 +12,7 @@ $CachePath = 'C:\npm\cache'
New-Item -Path $PrefixPath -Force -ItemType Directory New-Item -Path $PrefixPath -Force -ItemType Directory
New-Item -Path $CachePath -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 Add-MachinePathItem $PrefixPath
$env:Path = Get-MachinePath $env:Path = Get-MachinePath

View File

@@ -3,4 +3,4 @@
## Desc: Install OpenSSL ## 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 # Install latest PHP in chocolatey
$installDir = "c:\tools\php" $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 # 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. # 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 ((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 ## Desc: Install Packer
################################################################################ ################################################################################
choco install packer -y Choco-Install -PackageName packer

View File

@@ -3,4 +3,4 @@
## Desc: Install Perl ## 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. # Install the latest version of sbt.
# See https://chocolatey.org/packages/sbt # See https://chocolatey.org/packages/sbt
choco install sbt -y Choco-Install -PackageName sbt
$env:SBT_HOME="${env:ProgramFiles(x86)}\sbt" $env:SBT_HOME="${env:ProgramFiles(x86)}\sbt"

View File

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

View File

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

View File

@@ -3,9 +3,9 @@
## Desc: Install WIX. ## 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) if(Test-IsWin19)
{ {

View File

@@ -3,4 +3,4 @@
## Desc: Install zstd ## 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 Remove-Item -Path $env:ChocolateyInstall\bin\cpack.exe -Force
# Install webpi # Install webpi
choco install webpicmd -y Choco-Install -PackageName webpicmd
# Install vcredist140
Choco-Install -PackageName vcredist140
# Expand disk size of OS drive # 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 Remove-Item -Path $env:ChocolateyInstall\bin\cpack.exe -Force
# Install webpi # Install webpi
choco install webpicmd -y Choco-Install -PackageName webpicmd
# Expand disk size of OS drive # Expand disk size of OS drive