diff --git a/eng/helix/content/Download.ps1 b/eng/helix/content/Download.ps1 new file mode 100644 index 000000000000..1198af6a2034 --- /dev/null +++ b/eng/helix/content/Download.ps1 @@ -0,0 +1,47 @@ + <# + .SYNOPSIS + Downloads a given URI and saves it to outputFile + .DESCRIPTION + Downloads a given URI and saves it to outputFile + PARAMETER uri + The URI to fetch +.PARAMETER outputFile + The outputh file path to save the URI +#> +param( + [Parameter(Mandatory = $true)] + $uri, + + [Parameter(Mandatory = $true)] + $outputFile +) +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$ProgressPreference = 'SilentlyContinue' # Don't display the console progress UI - it's a huge perf hit + +$maxRetries = 5 +$retries = 1 + +while($true) { + try { + Write-Host "GET $uri" + Invoke-WebRequest $uri -OutFile $outputFile + break + } + catch { + Write-Host "Failed to download '$uri'" + $error = $_.Exception.Message + } + + if (++$retries -le $maxRetries) { + Write-Warning $error -ErrorAction Continue + $delayInSeconds = [math]::Pow(2, $retries) - 1 # Exponential backoff + Write-Host "Retrying. Waiting for $delayInSeconds seconds before next attempt ($retries of $maxRetries)." + Start-Sleep -Seconds $delayInSeconds + } + else { + Write-Error $error -ErrorAction Continue + throw "Unable to download file in $maxRetries attempts." + } + } + +Write-Host "Download of '$uri' complete, saved to $outputFile..." diff --git a/eng/helix/content/InstallDotNet.ps1 b/eng/helix/content/InstallDotNet.ps1 new file mode 100644 index 000000000000..7e8786643355 --- /dev/null +++ b/eng/helix/content/InstallDotNet.ps1 @@ -0,0 +1,35 @@ + <# + .SYNOPSIS + Installs dotnet sdk and runtime using https://dot.net/v1/dotnet-install.ps1 + .DESCRIPTION + Installs dotnet sdk and runtime using https://dot.net/v1/dotnet-install.ps1 +.PARAMETER arch + The architecture to install. +.PARAMETER sdkVersion + The sdk version to install +.PARAMETER runtimeVersion + The runtime version to install +.PARAMETER installDir + The directory to install to +#> +param( + [Parameter(Mandatory = $true)] + $arch, + + [Parameter(Mandatory = $true)] + $sdkVersion, + + [Parameter(Mandatory = $true)] + $runtimeVersion, + + [Parameter(Mandatory = $true)] + $installDir +) + +& $PSScriptRoot\Download.ps1 "https://dot.net/v1/dotnet-install.ps1" $PSScriptRoot\dotnet-install.ps1 +Write-Host "Download of dotnet-install.ps1 complete..." +Write-Host "Installing SDK...& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Version $sdkVersion -InstallDir $installDir" +Invoke-Expression "& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Version $sdkVersion -InstallDir $installDir" +Write-Host "Installing Runtime...& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Runtime dotnet -Version $runtimeVersion -InstallDir $installDir" +Invoke-Expression "& $PSScriptRoot\dotnet-install.ps1 -Architecture $arch -Runtime dotnet -Version $runtimeVersion -InstallDir $installDir" +Write-Host "InstallDotNet.ps1 complete..." \ No newline at end of file diff --git a/eng/helix/content/InstallJdk.ps1 b/eng/helix/content/InstallJdk.ps1 index a9346062fad6..ac47e2005cd2 100644 --- a/eng/helix/content/InstallJdk.ps1 +++ b/eng/helix/content/InstallJdk.ps1 @@ -45,7 +45,7 @@ Remove-Item -Force -Recurse $tempDir -ErrorAction Ignore | out-null mkdir $tempDir -ea Ignore | out-null mkdir $installDir -ea Ignore | out-null Write-Host "Starting download of JDK ${JdkVersion}" -Invoke-WebRequest -UseBasicParsing -Uri "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/java/jdk-${JdkVersion}_windows-x64_bin.zip" -OutFile "$tempDir/jdk.zip" +& $PSScriptRoot\Download.ps1 "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/java/jdk-${JdkVersion}_windows-x64_bin.zip" $tempDir/jdk.zip Write-Host "Done downloading JDK ${JdkVersion}" Add-Type -assembly "System.IO.Compression.FileSystem" diff --git a/eng/helix/content/InstallNode.ps1 b/eng/helix/content/InstallNode.ps1 index 3754eee5f556..224a8b92b2f3 100644 --- a/eng/helix/content/InstallNode.ps1 +++ b/eng/helix/content/InstallNode.ps1 @@ -38,7 +38,7 @@ if (Test-Path "$InstallDir\node.exe") $nodeFile="node-v$Version-win-x64" $url="http://nodejs.org/dist/v$Version/$nodeFile.zip" Write-Host "Starting download of NodeJs ${Version} from $url" -Invoke-WebRequest -UseBasicParsing -Uri "$url" -OutFile "nodejs.zip" +& $PSScriptRoot\Download.ps1 $url nodejs.zip Write-Host "Done downloading NodeJS ${Version}" $tempPath = [System.IO.Path]::GetTempPath() diff --git a/eng/helix/content/mssql/InstallSqlServerLocalDB.ps1 b/eng/helix/content/mssql/InstallSqlServerLocalDB.ps1 index 8621112ac657..c3a04cec2795 100644 --- a/eng/helix/content/mssql/InstallSqlServerLocalDB.ps1 +++ b/eng/helix/content/mssql/InstallSqlServerLocalDB.ps1 @@ -31,8 +31,7 @@ $installerFilename = "SqlLocalDB.msi" $installerPath = "$intermedateDir\$installerFilename" Write-Host "" Write-Host "Downloading '$installerFilename' to '$installerPath'." -Invoke-WebRequest -OutFile $installerPath -UseBasicParsing ` - -Uri 'https://download.microsoft.com/download/9/0/7/907AD35F-9F9C-43A5-9789-52470555DB90/ENU/SqlLocalDB.msi' +& $PSScriptRoot\Download.ps1 'https://download.microsoft.com/download/9/0/7/907AD35F-9F9C-43A5-9789-52470555DB90/ENU/SqlLocalDB.msi' $installerPath # Install LocalDB. $arguments = '/package', "`"$installerPath`"", '/NoRestart', '/Passive', ` diff --git a/eng/helix/content/runtests.cmd b/eng/helix/content/runtests.cmd index 0b6e89c3cdf6..13879c7f415d 100644 --- a/eng/helix/content/runtests.cmd +++ b/eng/helix/content/runtests.cmd @@ -24,10 +24,8 @@ set DOTNET_CLI_HOME=%HELIX_CORRELATION_PAYLOAD%\home set PATH=%DOTNET_ROOT%;!PATH!;%HELIX_CORRELATION_PAYLOAD%\node\bin echo Set path to: %PATH% -echo "Installing SDK" -powershell.exe -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'))) -Architecture %$arch% -Version %$sdkVersion% -InstallDir %DOTNET_ROOT%" -echo "Installing Runtime" -powershell.exe -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'))) -Architecture %$arch% -Runtime dotnet -Version %$runtimeVersion% -InstallDir %DOTNET_ROOT%" +echo "Invoking InstallDotNet.ps1 %$arch% %$sdkVersion% %$runtimeVersion% %DOTNET_ROOT%" +powershell.exe -NoProfile -ExecutionPolicy unrestricted -file InstallDotNet.ps1 %$arch% %$sdkVersion% %$runtimeVersion% %DOTNET_ROOT% set exit_code=0 echo "Restore: dotnet restore RunTests\RunTests.csproj --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json --ignore-failed-sources..." diff --git a/eng/scripts/Download.ps1 b/eng/scripts/Download.ps1 new file mode 100644 index 000000000000..f730f009c29a --- /dev/null +++ b/eng/scripts/Download.ps1 @@ -0,0 +1,47 @@ + <# + .SYNOPSIS + Downloads a given uri and saves it to outputFile + .DESCRIPTION + Downloads a given uri and saves it to outputFile + PARAMETER uri + The uri to fetch +.PARAMETER outputFile + The outputh file path to save the uri +#> +param( + [Parameter(Mandatory = $true)] + $uri, + + [Parameter(Mandatory = $true)] + $outputFile +) +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$ProgressPreference = 'SilentlyContinue' # Don't display the console progress UI - it's a huge perf hit + +$maxRetries = 5 +$retries = 1 + +while($true) { + try { + Write-Host "GET $uri" + Invoke-WebRequest $uri -OutFile $outputFile + break + } + catch { + Write-Host "Failed to download '$uri'" + $error = $_.Exception.Message + } + + if (++$retries -le $maxRetries) { + Write-Warning $error -ErrorAction Continue + $delayInSeconds = [math]::Pow(2, $retries) - 1 # Exponential backoff + Write-Host "Retrying. Waiting for $delayInSeconds seconds before next attempt ($retries of $maxRetries)." + Start-Sleep -Seconds $delayInSeconds + } + else { + Write-Error $error -ErrorAction Continue + throw "Unable to download file in $maxRetries attempts." + } + } + +Write-Host "Download of '$uri' complete, saved to $outputFile..." diff --git a/eng/scripts/InstallGoogleChrome.ps1 b/eng/scripts/InstallGoogleChrome.ps1 index 8546095e46c4..2159c7de09d1 100644 --- a/eng/scripts/InstallGoogleChrome.ps1 +++ b/eng/scripts/InstallGoogleChrome.ps1 @@ -1,4 +1,4 @@ $InstallerPath = "$env:Temp\chrome_installer.exe"; -Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $InstallerPath; +& $PSScriptRoot\Download.ps1 "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" $InstallerPath Start-Process -FilePath $InstallerPath -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $InstallerPath diff --git a/eng/scripts/InstallJdk.ps1 b/eng/scripts/InstallJdk.ps1 index 3602b6e734ad..f11ae1e640eb 100644 --- a/eng/scripts/InstallJdk.ps1 +++ b/eng/scripts/InstallJdk.ps1 @@ -39,7 +39,7 @@ Remove-Item -Force -Recurse $tempDir -ErrorAction Ignore | out-null mkdir $tempDir -ea Ignore | out-null mkdir $installDir -ea Ignore | out-null Write-Host "Starting download of JDK ${JdkVersion}" -Invoke-WebRequest -UseBasicParsing -Uri "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/java/jdk-${JdkVersion}_windows-x64_bin.zip" -Out "$tempDir/jdk.zip" +& $PSScriptRoot\Download.ps1 "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/java/jdk-${JdkVersion}_windows-x64_bin.zip" "$tempDir/jdk.zip" Write-Host "Done downloading JDK ${JdkVersion}" Expand-Archive "$tempDir/jdk.zip" -d "$tempDir/jdk/" Write-Host "Expanded JDK to $tempDir" diff --git a/eng/scripts/InstallProcDump.ps1 b/eng/scripts/InstallProcDump.ps1 index 92334ffb7b1e..ce2ce95cad7d 100644 --- a/eng/scripts/InstallProcDump.ps1 +++ b/eng/scripts/InstallProcDump.ps1 @@ -32,7 +32,7 @@ Remove-Item -Force -Recurse $tempDir -ErrorAction Ignore | out-null mkdir $tempDir -ea Ignore | out-null mkdir $installDir -ea Ignore | out-null Write-Host "Starting ProcDump download" -Invoke-WebRequest -UseBasicParsing -Uri "https://download.sysinternals.com/files/Procdump.zip" -Out "$tempDir/ProcDump.zip" +& $PSScriptRoot\Download.ps1 "https://download.sysinternals.com/files/Procdump.zip" "$tempDir/ProcDump.zip" Write-Host "Done downloading ProcDump" Expand-Archive "$tempDir/ProcDump.zip" -d "$tempDir/ProcDump/" Write-Host "Expanded ProcDump to $tempDir"