Skip to content

Commit 0795b9e

Browse files
[windows] warmup Azure CLI (#8427)
* [windows] warmup Azure CLI Improve Azure CLI first run timing. Follow up: #8294 Co-authored-by: Jesse Houwing <jesse.houwing@gmail.com> * expose AZURE_EXTENSION_DIR to image generation * suppress az warmup output * refresh PATH before warmup --------- Co-authored-by: Jesse Houwing <jesse.houwing@gmail.com>
1 parent fbaf4c6 commit 0795b9e

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

images/win/scripts/Installers/Install-AzureCli.ps1

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@
33
## Desc: Install Azure CLI
44
################################################################################
55

6-
Write-Host "Install the latest Azure CLI release"
7-
$azCliUrl = "https://aka.ms/installazurecliwindowsx64"
8-
Install-Binary -Url $azCliUrl -Name "azure-cli.msi"
6+
Write-Host 'Install the latest Azure CLI release'
7+
8+
$azureCliConfigPath = 'C:\azureCli'
9+
# Store azure-cli cache outside of the provisioning user's profile
10+
[Environment]::SetEnvironmentVariable('AZURE_CONFIG_DIR', $azureCliConfigPath, [System.EnvironmentVariableTarget]::Machine)
11+
# make variable to be available in the current session
12+
${env:AZURE_CONFIG_DIR} = $azureCliConfigPath
13+
14+
$azCliUrl = 'https://aka.ms/installazurecliwindowsx64'
15+
Install-Binary -Url $azCliUrl -Name 'azure-cli.msi'
916

1017
$azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory'
11-
$null = New-Item -ItemType "Directory" -Path $azureCliExtensionPath
18+
$null = New-Item -ItemType 'Directory' -Path $azureCliExtensionPath
19+
20+
[Environment]::SetEnvironmentVariable('AZURE_EXTENSION_DIR', $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine)
21+
# make variable to be available in the current session
22+
${env:AZURE_EXTENSION_DIR} = $azureCliExtensionPath
23+
24+
# Warm-up Azure CLI
25+
26+
Write-Host "Warmup 'az'"
1227

13-
[Environment]::SetEnvironmentVariable("AZURE_EXTENSION_DIR", $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine)
28+
$env:PATH = [Environment]::GetEnvironmentVariable('PATH', 'Machine')
29+
az --help | Out-Null
30+
if ($LASTEXITCODE -ne 0)
31+
{
32+
throw "Command 'az --help' failed"
33+
}
1434

15-
Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure CLI"
35+
Invoke-PesterTests -TestFile 'CLI.Tools' -TestName 'Azure CLI'

0 commit comments

Comments
 (0)