[windows] warmup Azure CLI (#8427)

* [windows] warmup Azure CLI

Improve Azure CLI first run timing.
Follow up: https://github.com/actions/runner-images/pull/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>
This commit is contained in:
ilia-shipitsin
2023-10-05 15:03:58 +02:00
committed by GitHub
parent fbaf4c67c6
commit 0795b9ed8b

View File

@@ -3,13 +3,33 @@
## Desc: Install Azure CLI
################################################################################
Write-Host "Install the latest Azure CLI release"
$azCliUrl = "https://aka.ms/installazurecliwindowsx64"
Install-Binary -Url $azCliUrl -Name "azure-cli.msi"
Write-Host 'Install the latest Azure CLI release'
$azureCliConfigPath = 'C:\azureCli'
# Store azure-cli cache outside of the provisioning user's profile
[Environment]::SetEnvironmentVariable('AZURE_CONFIG_DIR', $azureCliConfigPath, [System.EnvironmentVariableTarget]::Machine)
# make variable to be available in the current session
${env:AZURE_CONFIG_DIR} = $azureCliConfigPath
$azCliUrl = 'https://aka.ms/installazurecliwindowsx64'
Install-Binary -Url $azCliUrl -Name 'azure-cli.msi'
$azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory'
$null = New-Item -ItemType "Directory" -Path $azureCliExtensionPath
$null = New-Item -ItemType 'Directory' -Path $azureCliExtensionPath
[Environment]::SetEnvironmentVariable("AZURE_EXTENSION_DIR", $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable('AZURE_EXTENSION_DIR', $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine)
# make variable to be available in the current session
${env:AZURE_EXTENSION_DIR} = $azureCliExtensionPath
Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure CLI"
# Warm-up Azure CLI
Write-Host "Warmup 'az'"
$env:PATH = [Environment]::GetEnvironmentVariable('PATH', 'Machine')
az --help | Out-Null
if ($LASTEXITCODE -ne 0)
{
throw "Command 'az --help' failed"
}
Invoke-PesterTests -TestFile 'CLI.Tools' -TestName 'Azure CLI'