mirror of
https://github.com/actions/runner-images.git
synced 2025-12-24 10:28:00 +08:00
added DownloadWithRetry function
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
## File: Install-SQLExpress.ps1
|
||||
## Desc: Install SQL Express for Windows
|
||||
################################################################################
|
||||
Import-Module -Name ImageHelpers -Force;
|
||||
|
||||
function Download-FullSQLPackage {
|
||||
param(
|
||||
@@ -60,52 +61,14 @@ function Start-Installer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Start-DownloadSQLExpress {
|
||||
param(
|
||||
[String]$InstallerUrl,
|
||||
[String]$InstallerPath,
|
||||
[int] $retries = 10
|
||||
)
|
||||
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"
|
||||
}
|
||||
#default variables for functions.
|
||||
$installerUrl = "https://go.microsoft.com/fwlink/?linkid=866658"
|
||||
$installerPath = "${env:Temp}\SQL2019-SSEI-Expr.exe"
|
||||
$downloadPath = "C:\SQLEXPRESS2019"
|
||||
$setupPath = Join-Path $downloadPath "SQLEXPR_x64_ENU"
|
||||
#Set default location for proper script execution
|
||||
Set-Location -Path $downloadPath
|
||||
#Download installer for SQL Express
|
||||
Start-DownloadSQLExpress -InstallerUrl $installerUrl -InstallerPath $installerPath
|
||||
$installerPath = Start-DownloadWithRetry -Url "https://go.microsoft.com/fwlink/?linkid=866658" -Name SQL2019-SSEI-Expr.exe
|
||||
#Download full SQL Express package
|
||||
Download-FullSQLPackage -InstallerPath $installerPath
|
||||
#Unpack SQL Express Installer
|
||||
|
||||
Reference in New Issue
Block a user