From 81872a6a71eed002eda446b20630d0098a2cad33 Mon Sep 17 00:00:00 2001 From: "Dariy.Nurgaleev" Date: Wed, 18 Mar 2020 00:46:51 +0700 Subject: [PATCH] added retry logic for download --- .../scripts/Installers/Install-SQLExpress.ps1 | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/images/win/scripts/Installers/Install-SQLExpress.ps1 b/images/win/scripts/Installers/Install-SQLExpress.ps1 index 254d09bcd..2834371e3 100644 --- a/images/win/scripts/Installers/Install-SQLExpress.ps1 +++ b/images/win/scripts/Installers/Install-SQLExpress.ps1 @@ -25,10 +25,37 @@ function Start-Task { function Start-DownloadSQLExpress { param( [String]$InstallerUrl, - [String]$InstallerPath + [String]$InstallerPath, + [int] $retries = 10 ) - Write-Host "Download SQL Express web-installer from: $InstallerUrl" - (New-Object System.Net.WebClient).DownloadFile($InstallerUrl, $InstallerPath) + Write-Host "Downloading SQL Express web-installer from: $InstallerUrl" + # In case of any errors -try to download package several times + while($retries -gt 0) + { + try + { + Write-Host "Downloading SQL Express installer..." + (New-Object System.Net.WebClient).DownloadFile($InstallerUrl, $InstallerPath) + break + } + catch + { + Write-Host "There is an error during SQL Express downloading" + $_ + + $retries-- + + if ($retries -eq 0) + { + Write-Host "File can't be downloaded" + $_ + exit 1 + } + + Write-Host "Waiting 30 seconds before retrying. Retries left: $retries" + Start-Sleep -Seconds 30 + } + } Write-Host "SQL Express has been successfully downladed from the link: $InstallerUrl" }