Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 6 additions & 46 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ jobs:
TargetPath: 'build_scripts/windows/out/'
ArtifactName: msi-$(Platform)

- job: TestWindowsMSI
displayName: Test Windows MSI
- job: TestMsiInstallation
displayName: Test MSI Installation
strategy:
matrix:
x86:
Platform: x86
# x64:
# Platform: x64
x64:
Platform: x64

dependsOn: BuildWindowsMSI
condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule'))
Expand All @@ -257,47 +257,7 @@ jobs:
- task: PowerShell@2
displayName: Install and Load CLI
inputs:
targetType: inline
script: |
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
# Start another Powershell process as Admin and execute this script again
$arguments = "& '" +$myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
# Stop if the PowerShell is not run as Admin
Break
}
# The following are executed by elevated PowerShell
az --version

$InstallArgs = @(
"/i"
"`"$env:SYSTEM_ARTIFACTSDIRECTORY\msi\Microsoft Azure CLI.msi`""
"/q"
"/norestart"
"/l*v"
".\install_logs.txt"
)
$pre_installed_version=az version --query '\"azure-cli\"' -o tsv
$to_be_installed_version=Get-Content $(System.ArtifactsDirectory)/metadata/version
if ($pre_installed_version -eq $to_be_installed_version){
# See https://docs.microsoft.com/windows/win32/msi/reinstallmode about options of REINSTALLMODE
$reinstall_option="REINSTALL=ALL REINSTALLMODE=emus"
$InstallArgs += $reinstall_option
}
Start-Process "msiexec.exe" -ArgumentList $InstallArgs -Wait -NoNewWindow
$install_time=Measure-Command {Start-Process "msiexec.exe" -ArgumentList $InstallArgs -Wait -NoNewWindow} | select -expand TotalSeconds
$installed_version=az version --query '\"azure-cli\"' -o tsv
if ($installed_version -ne $to_be_installed_version){
echo "The MSI failed to install."
Exit 1
}
echo 'Install time(seconds):' $install_time
az --version
# Test bundled pip with extension installation
az extension add -n rdbms-connect
az self-test

Get-Content .\install_logs.txt
filePath: build_scripts\windows\scripts\test_msi_installation.ps1

- job: BuildDockerImage
displayName: Build Docker Image
Expand Down Expand Up @@ -1137,7 +1097,7 @@ jobs:
- VerifyWindowsRequirements
- VerifyVersions
- BuildWindowsMSI
- TestWindowsMSI
- TestMsiInstallation
- BuildDockerImage
- TestDockerImage
- BuildPythonWheel
Expand Down
76 changes: 76 additions & 0 deletions build_scripts/windows/scripts/test_msi_installation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

Set-PSDebug -Trace 1

if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
# Start another Powershell process as Admin and execute this script again
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
# Stop if the PowerShell is not run as Admin
Break
}
# The following are executed by elevated PowerShell

# Deal with the pre-installed Azure CLI on the ADO agent
az --version

# Uninstall the pre-installed Azure CLI. We use wildcard, since product name can be:
# - Microsoft Azure CLI --deprecated
# - Microsoft Azure CLI (32-bit)
# - Microsoft Azure CLI (64-bit)
$cli_package = Get-Package -Provider Programs -IncludeWindowsInstaller -Name "Microsoft Azure CLI*"
$cli_package | Format-List
Uninstall-Package -Name $cli_package.Name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, when we added a benchmark to monitor the MSI installation time https://github.com/Azure/azure-cli/compare/installation-benchmark, we uninstall Azure CLI MSI with

Uninstall-Package -Name "Microsoft Azure CLI"

so we use the same approach here.

However, Uninstall-Package only works in Windows PowerShell. The latest Uninstall-Package doesn't work in PowerShell Core. Still consulting PowerShell team for the modern solution.


# Make sure it is uninstalled
Get-Package -Provider Programs -IncludeWindowsInstaller


# Install artifact MSI
$InstallArgs = @(
"/i"
"`"$env:SYSTEM_ARTIFACTSDIRECTORY\msi\Microsoft Azure CLI.msi`""
"/q"
"/norestart"
"/l*v"
".\install_logs.txt"
)
Write-Output "Calling: msiexec.exe $InstallArgs"
$install_time = Measure-Command {Start-Process "msiexec.exe" -ArgumentList $InstallArgs -Wait -NoNewWindow}

# Show installation log. Since the log is too big, we only print it when needed.
# Get-Content .\install_logs.txt

# Show installation time
Write-Output "Installation time (seconds): $($install_time.TotalSeconds)"

# Show package information
Get-Package -Provider Programs -IncludeWindowsInstaller -Name "Microsoft Azure CLI*" | Format-List

# We can't restart the current shell in CI to refresh PATH, so use absolute path.
# If we can find a way to refresh PATH in the same shell session, we can directly call az.
if ($env:PLATFORM -eq 'x64') {
$az_full_path = "C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin\az.cmd"
} else {
$az_full_path = "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd"
}

& $az_full_path --version

$installed_version=& $az_full_path version --query '\"azure-cli\"' -o tsv
Write-Output "Installed version: $installed_version"

$artifact_version=Get-Content $env:SYSTEM_ARTIFACTSDIRECTORY\metadata\version
Write-Output "Artifact version: $artifact_version"

if ($installed_version -ne $artifact_version){
Write-Output "The installed version doesn't match the artifact version."
Exit 1
}

# Test bundled pip with extension installation
& $az_full_path extension add -n account
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rdbms-connect fails to install due to #25188, so we try a simpler extension account.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no equivalent of set -e from Bash in PowerShell for native commands (az.cmd), so $ErrorActionPreference = "Stop" doesn't work even if az fails with exit code 2. That's why even though rdbms-connect fails to install, the script still succeeds. For native commands, we must manually check $LastExitCode. Not sure if we want to do that here.

See https://stackoverflow.com/questions/9948517/how-to-stop-a-powershell-script-on-the-first-error

& $az_full_path self-test