Merge branch 'master' into v-dmshib/update-gem-latest

This commit is contained in:
Dmitry Shibanov
2020-01-20 16:48:23 +03:00
44 changed files with 1177 additions and 922 deletions

View File

@@ -16,4 +16,6 @@ Export-ModuleMember -Function @(
'Install-EXE'
'Add-ContentToMarkdown'
'Add-SoftwareDetailsToMarkdown'
'Stop-SvcWithErrHandling'
'Set-SvcWithErrHandling'
)

View File

@@ -81,3 +81,82 @@ function Install-EXE
return -1
}
}
function Stop-SvcWithErrHandling
<#
.DESCRIPTION
Function for stopping the Windows Service with error handling
.AUTHOR
Andrey Mishechkin v-andmis@microsoft.com
.PARAMETER -ServiceName
The name of stopping service
.PARAMETER -StopOnError
Switch for stopping the script and exit from PowerShell if one service is absent
#>
{
param (
[Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName,
[Parameter()] [switch] $StopOnError
)
Process {
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
if (-not $Service) {
Write-Warning "[!] Service [$ServiceName] is not found";
if ($StopOnError) {
exit 1;
}
}
else {
Write-Host "Try to stop service [$ServiceName]";
try {
Stop-Service -Name $ServiceName -Force;
$Service.WaitForStatus("Stopped", "00:01:00");
Write-Host "Service [$ServiceName] has been stopped successfuly";
}
catch {
Write-Error "[!] Failed to stop service [$ServiceName] with error:"
$_ | Out-String | Write-Error;
}
}
}
}
function Set-SvcWithErrHandling
<#
.DESCRIPTION
Function for setting the Windows Service parameter with error handling
.AUTHOR
Andrey Mishechkin v-andmis@microsoft.com
.PARAMETER -ServiceName
The name of stopping service
.PARAMETER -Arguments
Hashtable for service arguments
#>
{
param (
[Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName,
[Parameter(Mandatory)] [hashtable] $Arguments
)
Process {
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
if (-not $Service) {
Write-Warning "[!] Service [$ServiceName] is not found";
}
try {
Set-Service $ServiceName @Arguments;
}
catch {
Write-Error "[!] Failed to set service [$ServiceName] arguments with error:"
$_ | Out-String | Write-Error;
}
}
}

View File

@@ -1,51 +1,48 @@
################################################################################
## File: Download-ToolCache.ps1
## Team: CI-Build
## Desc: Download tool cache
################################################################################
Function InstallTool
{
Param
(
[System.Object]$ExecutablePath
Function Install-NpmPackage {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[System.String]
$Name,
[Parameter(Mandatory=$true)]
[System.String]
$NpmRegistry
)
Write-Host $ExecutablePath.DirectoryName
Set-Location -Path $ExecutablePath.DirectoryName
Get-Location | Write-Host
if (Test-Path 'tool.zip')
{
Expand-Archive 'tool.zip' -DestinationPath '.'
}
cmd.exe /c 'install_to_tools_cache.bat'
Write-Host "Installing npm '$Name' package from '$NpmRegistry'"
npm install $Name --registry=$NpmRegistry
}
$SourceUrl = "https://vstsagenttools.blob.core.windows.net/tools"
# HostedToolCache Path
$Dest = "C:/"
$Path = "hostedtoolcache/windows"
$env:Path = "C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy;" + $env:Path
Write-Host "Started AzCopy from $SourceUrl to $Dest"
AzCopy /Source:$SourceUrl /Dest:$Dest /S /V /Pattern:$Path
$ToolsDirectory = $Dest + $Path
$current = Get-Location
Set-Location -Path $ToolsDirectory
Get-ChildItem -Recurse -Depth 4 -Filter install_to_tools_cache.bat | ForEach-Object {
#In order to work correctly Python 3.4 x86 must be installed after x64, this is achieved by current toolcache catalog structure
InstallTool($_)
}
Set-Location -Path $current
# Define AGENT_TOOLSDIRECTORY environment variable
$env:AGENT_TOOLSDIRECTORY = $ToolsDirectory
setx AGENT_TOOLSDIRECTORY $ToolsDirectory /M
# Install HostedToolCache tools via NPM
$ToolVersionsFileContent = Get-Content -Path "$env:ROOT_FOLDER/toolcache.json" -Raw
$ToolVersions = ConvertFrom-Json -InputObject $ToolVersionsFileContent
$ToolVersions.PSObject.Properties | ForEach-Object {
$PackageName = $_.Name
$PackageVersions = $_.Value
$NpmPackages = $PackageVersions | ForEach-Object { "$PackageName@$_" }
foreach($NpmPackage in $NpmPackages) {
Install-NpmPackage -Name $NpmPackage -NpmRegistry $env:TOOLCACHE_REGISTRY
}
}
#junction point from the previous Python2 directory to the toolcache Python2
Write-Host "Create symlink to Python2"
$python2Dir = (Get-Item -Path ($ToolsDirectory + '/Python/2.7*/x64')).FullName
cmd.exe /c mklink /d "C:\Python27amd64" "$python2Dir"

View File

@@ -1,28 +1,16 @@
################################################################################
## File: Install-Boost.ps1
## File: Set-BoostRoot.ps1
## Team: CI-Build
## Desc: Install boost using tool cache
################################################################################
$ToolCache = 'C:\hostedtoolcache\windows\boost'
$BoostDirectory = Join-Path -Path $env:ProgramFiles -ChildPath "Boost"
$BoostVersionsToInstall = $env:BOOST_VERSIONS.split(',')
$BoostVersions = $env:BOOST_VERSIONS.split(',')
$BoostDefault = $env:BOOST_DEFAULT
foreach($BoostVersion in $BoostVersionsToInstall)
foreach($BoostVersion in $BoostVersions)
{
$ZipName = Join-Path -Path $ToolCache -ChildPath "boost_${BoostVersion}_msvc-14.1.zip"
if (-Not (Test-Path $ZipName))
{
Write-Host "$ZipName not found"
exit 1
}
Write-Host "Expanding $ZipName"
$BoostInstallationDir = Join-Path -Path $BoostDirectory -ChildPath $BoostVersion
# Expand-Archive slower for 70% than 7z
& "$env:ProgramFiles\7-Zip\7z.exe" x $ZipName -o"$BoostDirectory" -y
$EnvBoostPath = "BOOST_ROOT_{0}" -f ($BoostVersion.Replace('.', '_'))
setx $EnvBoostPath $BoostInstallationDir /M | Out-Null
@@ -36,10 +24,3 @@ foreach($BoostVersion in $BoostVersionsToInstall)
setx BOOST_ROOT $BoostInstallationDir /M | Out-Null
}
}
# Removing boost cache folder
Write-Host "Removing boost cache folder"
if (Test-Path $ToolCache)
{
Remove-Item -Path $ToolCache -Force -Recurse
}

View File

@@ -3,24 +3,40 @@
## Desc: Install Google Chrome
################################################################################
Import-Module -Name ImageHelpers -Force
Import-Module -Name ImageHelpers -Force;
$temp_install_dir = 'C:\Windows\Installer'
New-Item -Path $temp_install_dir -ItemType Directory -Force
$ChromeInstallerFile = "chrome_installer.exe";
$ChromeInstallerUri = "https://dl.google.com/chrome/install/375.126/${ChromeInstallerFile}";
Install-Exe -Url $ChromeInstallerUri -Name $ChromeInstallerFile -ArgumentList ("/silent", "/install")
Install-MSI -MsiUrl "https://seleniumwebdrivers.blob.core.windows.net/knownchromeversion/googlechromestandaloneenterprise64.msi" -MsiName "googlechromestandaloneenterprise64.msi"
Write-Host "Adding the firewall rule for Google update blocking";
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe";
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe"
$GoogleSvcs = ('gupdate','gupdatem');
$GoogleSvcs | Stop-SvcWithErrHandling -StopOnError;
$GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"};
$regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update";
$regGoogleUpdateChrome = "HKLM:\SOFTWARE\Policies\Google\Chrome";
($regGoogleUpdatePath, $regGoogleUpdateChrome) | ForEach-Object {
New-Item -Path $_ -Force;
}
$regGoogleParameters = @(
@{ Name = "AutoUpdateCheckPeriodMinutes"; Value = 00000000},
@{ Name = "UpdateDefault"; Value = 00000000 },
@{ Name = "DisableAutoUpdateChecksCheckboxValue"; Value = 00000001 },
@{ Name = "Update{8A69D345-D564-463C-AFF1-A69D9E530F96}"; Value = 00000000 },
@{ Path = $regGoogleUpdateChrome; Name = "DefaultBrowserSettingEnabled"; Value = 00000000 }
)
$regGoogleParameters | ForEach-Object {
$Arguments = $_;
if (-not ($Arguments.Path)) {
$Arguments.Add("Path", $regGoogleUpdatePath);
}
$Arguments.Add("Force", $true);
New-ItemProperty @Arguments;
}
Stop-Service -Name gupdate -Force
Set-Service -Name gupdate -StartupType "Disabled"
Stop-Service -Name gupdatem -Force
Set-Service -Name gupdatem -StartupType "Disabled"
New-Item -Path "HKLM:\SOFTWARE\Policies\Google\Update" -Force
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Update" -Name "AutoUpdateCheckPeriodMinutes" -Value 00000000 -Force
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Update" -Name "UpdateDefault" -Value 00000000 -Force
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Update" -Name "DisableAutoUpdateChecksCheckboxValue" -Value 00000001 -Force
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Update" -Name "Update{8A69D345-D564-463C-AFF1-A69D9E530F96}" -Value 00000000 -Force
New-Item -Path "HKLM:\SOFTWARE\Policies\Google\Chrome" -Force
New-ItemProperty "HKLM:\SOFTWARE\Policies\Google\Chrome" -Name "DefaultBrowserSettingEnabled" -Value 00000000 -Force

View File

@@ -54,7 +54,8 @@ function InstallAllValidSdks()
# Consider all channels except preview/eol channels.
# Sort the channels in ascending order
$dotnetChannels = $dotnetChannels.'releases-index' | Where-Object { !$_."support-phase".Equals('preview') -and !$_."support-phase".Equals('eol') } | Sort-Object { [Version] $_."channel-version" }
# HACK: Explicitly adding eol channel 2.2 for a grace period as this channel is wierdly marked as eol with no higher 2.x channel
$dotnetChannels = $dotnetChannels.'releases-index' | Where-Object { (!$_."support-phase".Equals('preview') -and !$_."support-phase".Equals('eol')) -or ($_."channel-version" -eq "2.2") } | Sort-Object { [Version] $_."channel-version" }
# Download installation script.
Invoke-WebRequest -Uri 'https://dot.net/v1/dotnet-install.ps1' -UseBasicParsing -OutFile 'dotnet-install.ps1'

View File

@@ -12,7 +12,4 @@ choco install git -y --package-parameters="/GitAndUnixToolsOnPath /WindowsTermin
# Disable GCM machine-wide
[Environment]::SetEnvironmentVariable("GCM_INTERACTIVE", "Never", [System.EnvironmentVariableTarget]::Machine)
Add-MachinePathItem "C:\Program Files\Git\mingw64\bin"
Add-MachinePathItem "C:\Program Files\Git\usr\bin"
Add-MachinePathItem "C:\Program Files\Git\bin"
exit 0

View File

@@ -0,0 +1,35 @@
################################################################################
## File: Install-Selenium.ps1
## Desc: Install Selenium Server standalone
################################################################################
# Acquire latest Selenium release number from GitHub API
$latestReleaseUrl = "https://api.github.com/repos/SeleniumHQ/selenium/releases/latest"
try {
$latestReleaseInfo = Invoke-RestMethod -Uri $latestReleaseUrl
} catch {
Write-Error $_
exit 1
}
Write-Debug $latestReleaseInfo
$seleniumVersionString = $latestReleaseInfo.name.Split(" ")[1]
Write-Debug $seleniumVersionString
$seleniumVersion = [version]::Parse($seleniumVersionString)
# Download Selenium
Write-Host "Downloading selenium-server-standalone v$seleniumVersion..."
$seleniumReleaseUrl = "https://selenium-release.storage.googleapis.com/$($seleniumVersion.ToString(2))/selenium-server-standalone-$($seleniumVersion.ToString(3)).jar"
New-Item -ItemType directory -Path "C:\selenium\"
$seleniumBinPath = "C:\selenium\selenium-server-standalone.jar"
try {
Invoke-WebRequest -UseBasicParsing -Uri $seleniumReleaseUrl -OutFile $seleniumBinPath
} catch {
Write-Error $_
exit 1
}
Write-Host "Add selenium jar to the environment variables..."
setx "SELENIUM_JAR_PATH" "$($seleniumBinPath)" /M
exit 0

View File

@@ -2,16 +2,58 @@
## File: Install-SeleniumWebDrivers.ps1
## Desc: Install Selenium Web Drivers
################################################################################
$DestinationPath = "$($env:SystemDrive)\";
$DriversZipFile = "SeleniumWebDrivers.zip"
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;
}
catch {
Write-Error "[!] Failed to download $DriverZipFile";
exit 1;
}
Invoke-WebRequest -UseBasicParsing -Uri "https://seleniumwebdrivers.blob.core.windows.net/seleniumwebdrivers/SeleniumWebDrivers.zip" -OutFile SeleniumWebDrivers.zip
Expand-Archive -Path $DriversZipFile -DestinationPath $DestinationPath -Force;
Remove-Item $DriversZipFile;
Expand-Archive -Path SeleniumWebDrivers.zip -DestinationPath "C:\" -Force
$ChromeDriverPath = "$DestinationPath\SeleniumWebDrivers\ChromeDriver";
Write-Host "Chrome driver path: [$ChromeDriverPath]";
Remove-Item -Path "$ChromeDriverPath\*" -Force;
Remove-Item SeleniumWebDrivers.zip
$ChromePath = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe').'(default)';
[version]$ChromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion;
Write-Host "Chrome version: [$ChromeVersion]";
setx IEWebDriver "C:\SeleniumWebDrivers\IEDriver" /M
setx GeckoWebDriver "C:\SeleniumWebDrivers\GeckoDriver" /M
setx ChromeWebDriver "C:\SeleniumWebDrivers\ChromeDriver" /M
$ChromeDriverVersionUri = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$($ChromeVersion.Major).$($ChromeVersion.Minor).$($ChromeVersion.Build)";
Write-Host "Chrome driver version Uri [$ChromeDriverVersionUri]";
Write-Host "Getting the Chrome driver version...";
$ChromeDriverVersion = Invoke-WebRequest -Uri $ChromeDriverVersionUri;
Write-Host "Current Chrome driver version: [$ChromeDriverVersion]";
exit 0
$ChromeDriverZipDownloadUri = "https://chromedriver.storage.googleapis.com/$($ChromeDriverVersion.ToString())/chromedriver_win32.zip";
Write-Host "Chrome driver zip file download Uri: [$ChromeDriverZipDownloadUri]";
$DestFile= "$ChromeDriverPath\chromedriver_win32.zip";
$ChromeDriverVersion.Content | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force;
Write-Host "Chrome driver download....";
Invoke-WebRequest -Uri $ChromeDriverZipDownloadUri -OutFile $DestFile;
Write-Host "Chrome driver install....";
Expand-Archive -Path "$ChromeDriverPath\chromedriver_win32.zip" -DestinationPath $ChromeDriverPath -Force;
Remove-Item -Path "$ChromeDriverPath\chromedriver_win32.zip" -Force;
Write-Host "Setting the environment variables";
setx IEWebDriver "C:\SeleniumWebDrivers\IEDriver" /M;
setx GeckoWebDriver "C:\SeleniumWebDrivers\GeckoDriver" /M;
setx ChromeWebDriver "C:\SeleniumWebDrivers\ChromeDriver" /M;
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\';
$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path';
$PathValue += ";C:\SeleniumWebDrivers\ChromeDriver\";
Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $PathValue;
exit 0;

View File

@@ -6,5 +6,5 @@
Write-Host "Run windows updates"
Install-Module -Name PSWindowsUpdate -Force -AllowClobber
Get-WUInstall -WindowsUpdate -AcceptAll -UpdateType Software -IgnoreReboot
Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreUserInput -IgnoreReboot
Get-WUInstall -WindowsUpdate -AcceptAll -Install -UpdateType Software -IgnoreReboot
Get-WUInstall -MicrosoftUpdate -AcceptAll -Install -IgnoreUserInput -IgnoreReboot

View File

@@ -12,6 +12,21 @@ function GetChildFolders {
return Get-ChildItem -Path $Path -Directory -Name
}
function Get-ToolcachePackages {
$toolcachePath = Join-Path $env:ROOT_FOLDER "toolcache.json"
return Get-Content -Raw $toolcachePath | ConvertFrom-Json
}
$packages = (Get-ToolcachePackages).PSObject.Properties | ForEach-Object {
$packageNameParts = $_.Name.Split("-")
$toolName = $packageNameParts[1]
return [PSCustomObject] @{
ToolName = $packageNameParts[1]
Versions = $_.Value
Arch = $packageNameParts[3]
}
}
function ToolcacheTest {
param (
[Parameter(Mandatory = $True)]
@@ -22,36 +37,53 @@ function ToolcacheTest {
if (Test-Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName")
{
$description = ""
[array]$versions = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName"
if ($versions.count -gt 0){
foreach ($version in $versions)
[array]$installedVersions = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName"
if ($installedVersions.count -gt 0){
$softwarePackages = $packages | Where-Object { $_.ToolName -eq $SoftwareName }
foreach($softwarePackage in $softwarePackages)
{
$architectures = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version"
Write-Host "$SoftwareName version - $version : $([system.String]::Join(",", $architectures))"
foreach ($arch in $architectures)
foreach ($version in $softwarePackage.Versions)
{
$path = "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version\$arch"
foreach ($test in $ExecTests)
{
if (Test-Path "$path\$test")
{
Write-Host "$SoftwareName($test) $version($arch) is successfully installed:"
Write-Host (& "$path\$test" --version)
$foundVersion = $installedVersions | where { $_.StartsWith($version) }
if ($foundVersion -ne $null){
$architectures = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion"
$softwareArch = $softwarePackage.Arch
if ($architectures -Contains $softwareArch) {
$path = "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion\$softwareArch"
foreach ($test in $ExecTests)
{
if (Test-Path "$path\$test")
{
Write-Host "$SoftwareName($test) $foundVersion($softwareArch) is successfully installed:"
Write-Host (& "$path\$test" --version)
}
else
{
Write-Host "$SoftwareName($test) $foundVersion ($softwareArch) is not installed"
exit 1
}
}
$description += "_Version:_ $foundVersion ($softwareArch)<br/>"
}
else
{
Write-Host "$SoftwareName($test) $version ($arch) is not installed"
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion does not include required architecture"
exit 1
}
}
$description += "_Version:_ $version ($arch)<br/>"
else
{
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version.* was not found"
exit 1
}
}
}
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $description
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $description
}
}
else
{

View File

@@ -119,9 +119,9 @@ wmic logicaldisk get size,freespace,caption
# Adding description of the software to Markdown
$Content = @"
# Azure Pipelines Hosted VS2017 image
# Windows Server 2016
The following software is installed on machines in the Azure Pipelines **Hosted VS2017** (v$env:ImageVersion) pool.
The following software is installed on machines with the $env:ImageVersion update.
Components marked with **\*** have been upgraded since the previous version of the image.

View File

@@ -118,9 +118,9 @@ wmic logicaldisk get size,freespace,caption
# Adding description of the software to Markdown
$Content = @"
# Azure Pipelines Hosted Windows 2019 with VS2019 image
# Windows Server 2019
The following software is installed on machines in the Azure Pipelines **Hosted Windows 2019 with VS2019** (v$env:ImageVersion) pool.
The following software is installed on machines with the $env:ImageVersion update.
Components marked with **\*** have been upgraded since the previous version of the image.