From 0795b9ed8be55c2c08f33647e103f70dd18d9df6 Mon Sep 17 00:00:00 2001 From: ilia-shipitsin <125650415+ilia-shipitsin@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:03:58 +0200 Subject: [PATCH] [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 * expose AZURE_EXTENSION_DIR to image generation * suppress az warmup output * refresh PATH before warmup --------- Co-authored-by: Jesse Houwing --- .../scripts/Installers/Install-AzureCli.ps1 | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index c76c8f5073cb..8b3af147f4c0 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -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) +# make variable to be available in the current session +${env:AZURE_EXTENSION_DIR} = $azureCliExtensionPath + +# Warm-up Azure CLI + +Write-Host "Warmup 'az'" -[Environment]::SetEnvironmentVariable("AZURE_EXTENSION_DIR", $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine) +$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" \ No newline at end of file +Invoke-PesterTests -TestFile 'CLI.Tools' -TestName 'Azure CLI'