diff --git a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 index 94ff7b204ecd..c2007855af07 100644 --- a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 +++ b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 @@ -29,4 +29,5 @@ Export-ModuleMember -Function @( 'Test-IsWin19' 'Test-IsWin16' 'Choco-Install' + 'Extract-7Zip' ) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 8ec49e0d4b43..7f3806a13e20 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -386,3 +386,22 @@ function Test-IsWin16 { (Get-WinVersion) -match "2016" } + +function Extract-7Zip { + param + ( + [Parameter(Mandatory=$true)] + [string]$Path, + [Parameter(Mandatory=$true)] + [string]$DestinationPath + ) + + Write-Host "Expand archive '$PATH' to '$DestinationPath' directory" + 7z.exe x "$Path" -o"$DestinationPath" -y | Out-Null + + if ($LASTEXITCODE -ne 0) + { + Write-Host "There is an error during expanding '$Path' to '$DestinationPath' directory" + exit 1 + } +} diff --git a/images/win/scripts/Installers/Install-Chrome.ps1 b/images/win/scripts/Installers/Install-Chrome.ps1 index 22b477b28aec..f0eecc4c27da 100644 --- a/images/win/scripts/Installers/Install-Chrome.ps1 +++ b/images/win/scripts/Installers/Install-Chrome.ps1 @@ -66,7 +66,7 @@ $ChromeDriverZipDownloadUrl = "https://chromedriver.storage.googleapis.com/${Chr $ChromeDriverArchPath = Start-DownloadWithRetry -Url $ChromeDriverZipDownloadUrl -Name $ChromeDriverArchName Write-Host "Expand Chrome WebDriver archive..." -Expand-Archive -Path $ChromeDriverArchPath -DestinationPath $ChromeDriverPath -Force +Extract-7Zip -Path $ChromeDriverArchPath -DestinationPath $ChromeDriverPath Write-Host "Setting the environment variables..." setx ChromeWebDriver "$ChromeDriverPath" /M diff --git a/images/win/scripts/Installers/Install-CloudFoundryCli.ps1 b/images/win/scripts/Installers/Install-CloudFoundryCli.ps1 index 194ed5a3867b..6f9ea886bbf2 100644 --- a/images/win/scripts/Installers/Install-CloudFoundryCli.ps1 +++ b/images/win/scripts/Installers/Install-CloudFoundryCli.ps1 @@ -17,7 +17,7 @@ New-Item -Path $CloudFoundryCliPath -ItemType Directory -Force # Extract the zip archive Write-Host "Extracting cf cli..." -Expand-Archive -Path $CloudFoundryArchPath -DestinationPath $CloudFoundryCliPath -Force +Extract-7Zip -Path $CloudFoundryArchPath -DestinationPath $CloudFoundryCliPath # Add cf to path Add-MachinePathItem $CloudFoundryCliPath \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-Edge.ps1 b/images/win/scripts/Installers/Install-Edge.ps1 index c10f24226b80..85b828fb606e 100644 --- a/images/win/scripts/Installers/Install-Edge.ps1 +++ b/images/win/scripts/Installers/Install-Edge.ps1 @@ -29,7 +29,7 @@ $EdgeDriverDownloadUrl="https://msedgedriver.azureedge.net/${EdgeDriverLatestVer $EdgeDriverArchPath = Start-DownloadWithRetry -Url $EdgeDriverDownloadUrl -Name $EdgeDriverArchName Write-Host "Expand Microsoft Edge WebDriver archive..." -Expand-Archive -Path $EdgeDriverArchPath -DestinationPath $EdgeDriverPath -Force +Extract-7Zip -Path $EdgeDriverArchPath -DestinationPath $EdgeDriverPath Write-Host "Setting the environment variables..." setx EdgeWebDriver "$EdgeDriverPath" /M diff --git a/images/win/scripts/Installers/Install-Firefox.ps1 b/images/win/scripts/Installers/Install-Firefox.ps1 index efd3fe8b47d7..8817bf013198 100644 --- a/images/win/scripts/Installers/Install-Firefox.ps1 +++ b/images/win/scripts/Installers/Install-Firefox.ps1 @@ -45,7 +45,7 @@ $GeckoDriverDownloadUrl = $GeckoDriverWindowsAsset.browser_download_url $GeckoDriverArchPath = Start-DownloadWithRetry -Url $GeckoDriverDownloadUrl -Name $GeckoDriverArchName Write-Host "Expand Gecko WebDriver archive..." -Expand-Archive -Path $GeckoDriverArchPath -DestinationPath $GeckoDriverPath -Force +Extract-7Zip -Path $GeckoDriverArchPath -DestinationPath $GeckoDriverPath Write-Host "Setting the environment variables..." Add-MachinePathItem -PathItem $GeckoDriverPath diff --git a/images/win/scripts/Installers/Install-Go.ps1 b/images/win/scripts/Installers/Install-Go.ps1 index c5d4c144c32d..c37c54cf8a23 100644 --- a/images/win/scripts/Installers/Install-Go.ps1 +++ b/images/win/scripts/Installers/Install-Go.ps1 @@ -15,7 +15,7 @@ function Install-GoVersion [Switch] $addToDefaultPath ) - $latestVersionObject = $refsJson | Where-Object { $_.ref -Match "refs/tags/go$goVersion[./d]*" } | Select-Object -Last 1 + $latestVersionObject = $refsJson | Where-Object { $_.ref -Match "refs/tags/go$goVersion[./d]*" } | Select-Object -Last 1 $latestVersion = $latestVersionObject.ref.replace('refs/tags/go','') # Download the Go zip archive. @@ -30,7 +30,7 @@ function Install-GoVersion # Extract the zip archive. It contains a single directory named "go". Write-Host "Extracting Go $latestVersion..." $toolDirectory = Join-Path $env:AGENT_TOOLSDIRECTORY "go\$latestVersion" - 7z.exe x $goArchPath -o"$toolDirectory" -y | Out-Null + Extract-7Zip -Path $goArchPath -DestinationPath $toolDirectory # Rename the extracted "go" directory to "x64" for full path "C:\hostedtoolcache\windows\Go\1.14.2\x64\..." Rename-Item -path "$toolDirectory\go" -newName "x64" diff --git a/images/win/scripts/Installers/Install-IEWebDriver.ps1 b/images/win/scripts/Installers/Install-IEWebDriver.ps1 index 7dfd8b42f2d9..87104c1aab9d 100644 --- a/images/win/scripts/Installers/Install-IEWebDriver.ps1 +++ b/images/win/scripts/Installers/Install-IEWebDriver.ps1 @@ -2,21 +2,21 @@ ## File: Install-SeleniumWebDrivers.ps1 ## Desc: Install Selenium Web Drivers ################################################################################ -$DestinationPath = "$($env:SystemDrive)\"; +$DestinationPath = "$($env:SystemDrive)\" $DriversZipFile = "SeleniumWebDrivers.zip" -Write-Host "Destination path: [$DestinationPath]"; -Write-Host "Selenium drivers download and install..."; +Write-Host "Destination path: [$DestinationPath]" +Write-Host "Selenium drivers download and install..." try { - Invoke-WebRequest -UseBasicParsing -Uri "https://seleniumwebdrivers.blob.core.windows.net/seleniumwebdrivers/${DriversZipFile}" -OutFile $DriversZipFile; + Invoke-WebRequest -UseBasicParsing -Uri "https://seleniumwebdrivers.blob.core.windows.net/seleniumwebdrivers/${DriversZipFile}" -OutFile $DriversZipFile } catch { - Write-Error "[!] Failed to download $DriversZipFile"; - exit 1; + Write-Error "[!] Failed to download $DriversZipFile" + exit 1 } $TempSeleniumDir = Join-Path $Env:TEMP "SeleniumWebDrivers" -Expand-Archive -Path $DriversZipFile -DestinationPath $Env:TEMP -Force; -Remove-Item $DriversZipFile; +Extract-7Zip -Path $DriversZipFile -DestinationPath $Env:TEMP +Remove-Item $DriversZipFile $SeleniumWebDriverPath = Join-Path $DestinationPath "SeleniumWebDrivers" $IEDriverPathTemp = Join-Path $TempSeleniumDir 'IEDriver' @@ -29,4 +29,4 @@ Move-Item -Path "$IEDriverPathTemp" -Destination $SeleniumWebDriverPath Write-Host "Setting the environment variables" -setx IEWebDriver "C:\SeleniumWebDrivers\IEDriver" /M; +setx IEWebDriver "C:\SeleniumWebDrivers\IEDriver" /M diff --git a/images/win/scripts/Installers/Install-JavaTools.ps1 b/images/win/scripts/Installers/Install-JavaTools.ps1 index 455283d09a9d..34e9fb886580 100644 --- a/images/win/scripts/Installers/Install-JavaTools.ps1 +++ b/images/win/scripts/Installers/Install-JavaTools.ps1 @@ -82,6 +82,6 @@ $uri = 'https://ayera.dl.sourceforge.net/project/cobertura/cobertura/2.1.1/cober $coberturaPath = "C:\cobertura-2.1.1" $archivePath = Start-DownloadWithRetry -Url $uri -Name "cobertura.zip" -Expand-Archive -Path $archivePath -DestinationPath "C:\" +Extract-7Zip -Path $archivePath -DestinationPath "C:\" setx COBERTURA_HOME $coberturaPath /M diff --git a/images/win/scripts/Installers/Install-MysqlCli.ps1 b/images/win/scripts/Installers/Install-MysqlCli.ps1 index a9db2f4295ed..36097643704d 100644 --- a/images/win/scripts/Installers/Install-MysqlCli.ps1 +++ b/images/win/scripts/Installers/Install-MysqlCli.ps1 @@ -22,7 +22,7 @@ Install-Binary -Url $InstallerURI -Name $InstallerName -ArgumentList $ArgumentLi $mysqlArchPath = Start-DownloadWithRetry -Url $MysqlVersionUrl -Name "mysql.zip" # Expand the zip -Expand-Archive -Path $mysqlArchPath -DestinationPath "C:\" -Force +Extract-7Zip -Path $mysqlArchPath -DestinationPath "C:\" # Adding mysql in system environment path Add-MachinePathItem $mysqlPath \ No newline at end of file