From 247967c9c4d2d640befdf0d9d2b6c2c986f38390 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Thu, 14 Sep 2023 18:57:04 +0200 Subject: [PATCH 01/21] Fixes slow startup of `az` and `az devops` Redirects the `.azure` folder to common program files Redirects the `.azure-devops` folder to common program files During warm-up calls `az` and `az devops` to cache python's objects Turns off disk logging, colorization and auto-update based on the `az init` automation recomendations. --- .../scripts/Installers/Install-AzureCli.ps1 | 20 +++++++++++++++++-- .../Installers/Install-AzureDevOpsCli.ps1 | 12 ++++++++++- images/win/scripts/Installers/Warmup-User.ps1 | 14 +++++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index c76c8f5073cb..b68ce779b487 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -7,9 +7,25 @@ Write-Host "Install the latest Azure CLI release" $azCliUrl = "https://aka.ms/installazurecliwindowsx64" Install-Binary -Url $azCliUrl -Name "azure-cli.msi" +# Store cli extensions outside of the provisioning user's profile $azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory' $null = New-Item -ItemType "Directory" -Path $azureCliExtensionPath - [Environment]::SetEnvironmentVariable("AZURE_EXTENSION_DIR", $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine) -Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure CLI" \ No newline at end of file +# Store cli config outside of the provisioning user's profile +$azureCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureCliDirectory' +$null = New-Item -ItemType "Directory" -Path $azureCliConfigPath +[Environment]::SetEnvironmentVariable("AZURE_CONFIG_DIR", $azureCliConfigPath, [System.EnvironmentVariableTarget]::Machine) + +$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") + +# Turn use automation recommended settings to speed up first-call on the hosted runner images. +az config set auto-upgrade.enable=false +az config set core.error_recommendation=off +az config set core.disable_progress_bar=true +az config set core.only_show_errors=true +az config set core.no_color=true +az config set logging.enable_log_file=no +az config set output.show_survey_link=no + +Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure CLI" diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index 1c7d1bbfdb8f..bc14f8f2f1bf 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -3,6 +3,16 @@ ## Desc: Install Azure DevOps CLI ################################################################################ +# Store azure-devops-cli cache outside of the provisioning user's profile +$azureDevOpsCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureDevOpsCliConfigDirectory' +$null = New-Item -ItemType "Directory" -Path $azureDevOpsCliConfigPath +[Environment]::SetEnvironmentVariable("AZURE_DEVOPS_EXT_CONFIG_DIR", $azureDevOpsCliConfigPath, [System.EnvironmentVariableTarget]::Machine) + + +$azureDevOpsCliCachePath = Join-Path $azureDevOpsCliConfigPath "cache" +$null = New-Item -ItemType "Directory" -Path $azureDevOpsCliCachePath +[Environment]::SetEnvironmentVariable("AZURE_DEVOPS_CACHE_DIR", $azureDevOpsCliCachePath, [System.EnvironmentVariableTarget]::Machine) + az extension add -n azure-devops -Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" \ No newline at end of file +Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" diff --git a/images/win/scripts/Installers/Warmup-User.ps1 b/images/win/scripts/Installers/Warmup-User.ps1 index 19dc41265a1e..880b172829d1 100644 --- a/images/win/scripts/Installers/Warmup-User.ps1 +++ b/images/win/scripts/Installers/Warmup-User.ps1 @@ -21,5 +21,15 @@ reg.exe load HKLM\DEFAULT c:\users\default\ntuser.dat reg.exe copy HKCU\Software\Microsoft\VisualStudio HKLM\DEFAULT\Software\Microsoft\VisualStudio /s reg.exe unload HKLM\DEFAULT - -Write-Host "Warmup-User.ps1 - completed" \ No newline at end of file +# speed up the azure CLI by keeping the cache after loading the extensions + +Write-Host "Warmup 'az'" +az --help | out-null +Write-Host "Warmup 'az-devops'" +az devops --help | out-null +az pipelines --help | out-null +az boards --help | out-null +az repos --help | out-null +az artifacts --help | out-null + +Write-Host "Warmup-User.ps1 - completed" From 62612052bf258764b11ab1241b1ac3ec0ec90330 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Tue, 19 Sep 2023 09:17:52 +0200 Subject: [PATCH 02/21] Adds helpers to refresh the `$env:path` --- .../win/scripts/ImageHelpers/ImageHelpers.psm1 | 3 +++ images/win/scripts/ImageHelpers/PathHelpers.ps1 | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 index f2ae79e4cf58..418c95cd4286 100644 --- a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 +++ b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 @@ -12,13 +12,16 @@ Export-ModuleMember -Function @( 'Disconnect-Hive' 'Test-MachinePath' 'Get-MachinePath' + 'Get-UserPath' 'Get-DefaultPath' 'Set-MachinePath' 'Set-DefaultPath' + 'Update-Path' 'Add-MachinePathItem' 'Add-DefaultPathItem' 'Add-DefaultItem' 'Get-SystemVariable' + 'Get-UserVariable' 'Get-DefaultVariable' 'Set-SystemVariable' 'Set-DefaultVariable' diff --git a/images/win/scripts/ImageHelpers/PathHelpers.ps1 b/images/win/scripts/ImageHelpers/PathHelpers.ps1 index df7ce10ed93e..7459241810f3 100644 --- a/images/win/scripts/ImageHelpers/PathHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/PathHelpers.ps1 @@ -33,6 +33,14 @@ function Disconnect-Hive { } } +function Get-UserVariable { + param( + [string]$UserVariable + ) + + [System.Environment]::GetEnvironmentVariable($SystemVariable, "User") +} + function Get-SystemVariable { param( [string]$SystemVariable @@ -80,10 +88,18 @@ function Set-DefaultVariable { [System.GC]::Collect() } +function Update-Path { + $env:Path = (Get-MachinePath) + ";" + (Get-UserPath) +} + function Get-MachinePath { Get-SystemVariable PATH } +function Get-UserPath { + Get-UserVariable PATH +} + function Get-DefaultPath { Get-DefaultVariable Path } From cd78c1f96352a6cf23f28836790a0f93adba0af3 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Tue, 19 Sep 2023 09:19:28 +0200 Subject: [PATCH 03/21] Uses environment functions from ImageHelpers --- images/win/scripts/Installers/Install-AzureCli.ps1 | 5 +++-- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index b68ce779b487..e1b45cfe0cea 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -6,16 +6,17 @@ Write-Host "Install the latest Azure CLI release" $azCliUrl = "https://aka.ms/installazurecliwindowsx64" Install-Binary -Url $azCliUrl -Name "azure-cli.msi" +Update-Path # Store cli extensions outside of the provisioning user's profile $azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory' $null = New-Item -ItemType "Directory" -Path $azureCliExtensionPath -[Environment]::SetEnvironmentVariable("AZURE_EXTENSION_DIR", $azureCliExtensionPath, [System.EnvironmentVariableTarget]::Machine) +Set-SystemVariable -SystemVariable "AZURE_EXTENSION_DIR" -value $azureCliExtensionPath # Store cli config outside of the provisioning user's profile $azureCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureCliDirectory' $null = New-Item -ItemType "Directory" -Path $azureCliConfigPath -[Environment]::SetEnvironmentVariable("AZURE_CONFIG_DIR", $azureCliConfigPath, [System.EnvironmentVariableTarget]::Machine) +Set-SystemVariable -SystemVariable "AZURE_CONFIG_DIR" -value $azureCliConfigPath $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index bc14f8f2f1bf..9e08068fd3c4 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -6,12 +6,12 @@ # Store azure-devops-cli cache outside of the provisioning user's profile $azureDevOpsCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureDevOpsCliConfigDirectory' $null = New-Item -ItemType "Directory" -Path $azureDevOpsCliConfigPath -[Environment]::SetEnvironmentVariable("AZURE_DEVOPS_EXT_CONFIG_DIR", $azureDevOpsCliConfigPath, [System.EnvironmentVariableTarget]::Machine) +Set-SystemVariable -SystemVariable "AZURE_DEVOPS_EXT_CONFIG_DIR" -value $azureDevOpsCliConfigPath $azureDevOpsCliCachePath = Join-Path $azureDevOpsCliConfigPath "cache" $null = New-Item -ItemType "Directory" -Path $azureDevOpsCliCachePath -[Environment]::SetEnvironmentVariable("AZURE_DEVOPS_CACHE_DIR", $azureDevOpsCliCachePath, [System.EnvironmentVariableTarget]::Machine) +Set-SystemVariable -SystemVariable "AZURE_DEVOPS_CACHE_DIR" -value $azureDevOpsCliCachePath az extension add -n azure-devops From 81b44e801c678ae08063ec249009147d02f57cc5 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Tue, 19 Sep 2023 09:20:03 +0200 Subject: [PATCH 04/21] Copies Invoke-ValidateCommand from the mac helpers --- .../scripts/ImageHelpers/ImageHelpers.psm1 | 1 + .../scripts/ImageHelpers/InstallHelpers.ps1 | 39 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 index 418c95cd4286..d1c05fb1ce5e 100644 --- a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 +++ b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 @@ -27,6 +27,7 @@ Export-ModuleMember -Function @( 'Set-DefaultVariable' 'Install-Binary' 'Install-VisualStudio' + 'Invoke-ValidateCommand' 'Get-ToolsetContent' 'Get-ToolsetToolFullPath' 'Stop-SvcWithErrHandling' diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index e5499625630e..36d8363845b6 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -720,4 +720,41 @@ function Test-FileSignature { } Write-Output "Signature for $FilePath is valid" -} \ No newline at end of file +} + +function Invoke-ValidateCommand { + param( + [Parameter(Mandatory)] + [string]$Command, + [Uint] $Timeout = 0 + ) + + if ($Timeout -eq 0) + { + $output = Invoke-Expression -Command $Command + if ($LASTEXITCODE -ne 0) { + throw "Command '$Command' has finished with exit code $LASTEXITCODE" + } + return $output + } + else + { + $job = $command | Start-Job -ScriptBlock { + $output = Invoke-Expression -Command $input + if ($LASTEXITCODE -ne 0) { + throw 'Command failed' + } + return $output + } + $waitObject = $job | Wait-Job -Timeout $Timeout + if(-not $waitObject) + { + throw "Command '$Command' has timed out" + } + if($waitObject.State -eq 'Failed') + { + throw "Command '$Command' has failed" + } + Receive-Job -Job $job + } +} From 3f65f32dcbc3d00ec2fbb931a6e5317b10d73b30 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Tue, 19 Sep 2023 09:22:02 +0200 Subject: [PATCH 05/21] Uses Invoke-ValidateCommand to configure az-zli and run warmup Moves warmup of az and az-devops to respective modules --- .../scripts/Installers/Install-AzureCli.ps1 | 20 ++++++++++--------- .../Installers/Install-AzureDevOpsCli.ps1 | 10 ++++++++-- images/win/scripts/Installers/Warmup-User.ps1 | 11 ---------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index e1b45cfe0cea..70ae7d74c134 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -18,15 +18,17 @@ $azureCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureCliDirectory' $null = New-Item -ItemType "Directory" -Path $azureCliConfigPath Set-SystemVariable -SystemVariable "AZURE_CONFIG_DIR" -value $azureCliConfigPath -$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") - # Turn use automation recommended settings to speed up first-call on the hosted runner images. -az config set auto-upgrade.enable=false -az config set core.error_recommendation=off -az config set core.disable_progress_bar=true -az config set core.only_show_errors=true -az config set core.no_color=true -az config set logging.enable_log_file=no -az config set output.show_survey_link=no +Write-Host "Setting automation defaults for 'az'" +Invoke-ValidateCommand -Command "az config set auto-upgrade.enable=false" +Invoke-ValidateCommand -Command "az config set core.error_recommendation=off" +Invoke-ValidateCommand -Command "az config set core.disable_progress_bar=true" +Invoke-ValidateCommand -Command "az config set core.no_color=true" +Invoke-ValidateCommand -Command "az config set logging.enable_log_file=no" +Invoke-ValidateCommand -Command "az config set output.show_survey_link=no" + +# Warm-up Azure CLI +Write-Host "Warmup 'az'" +Invoke-ValidateCommand -Command "az --help" Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure CLI" diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index 9e08068fd3c4..7236892e01d8 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -8,11 +8,17 @@ $azureDevOpsCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureDevOpsCliCon $null = New-Item -ItemType "Directory" -Path $azureDevOpsCliConfigPath Set-SystemVariable -SystemVariable "AZURE_DEVOPS_EXT_CONFIG_DIR" -value $azureDevOpsCliConfigPath - $azureDevOpsCliCachePath = Join-Path $azureDevOpsCliConfigPath "cache" $null = New-Item -ItemType "Directory" -Path $azureDevOpsCliCachePath Set-SystemVariable -SystemVariable "AZURE_DEVOPS_CACHE_DIR" -value $azureDevOpsCliCachePath -az extension add -n azure-devops +Invoke-ValidateCommand -Command "az extension add -n azure-devops" + +# Warm-up Azure DevOps CLI + +Write-Host "Warmup 'az-devops'" +@("devops", "pipelines", "boards", "repos", "artifacts") | ForEach-Object { + Invoke-ValidateCommand -Command "az $_ --help" +} Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" diff --git a/images/win/scripts/Installers/Warmup-User.ps1 b/images/win/scripts/Installers/Warmup-User.ps1 index 880b172829d1..3583f152fce1 100644 --- a/images/win/scripts/Installers/Warmup-User.ps1 +++ b/images/win/scripts/Installers/Warmup-User.ps1 @@ -21,15 +21,4 @@ reg.exe load HKLM\DEFAULT c:\users\default\ntuser.dat reg.exe copy HKCU\Software\Microsoft\VisualStudio HKLM\DEFAULT\Software\Microsoft\VisualStudio /s reg.exe unload HKLM\DEFAULT -# speed up the azure CLI by keeping the cache after loading the extensions - -Write-Host "Warmup 'az'" -az --help | out-null -Write-Host "Warmup 'az-devops'" -az devops --help | out-null -az pipelines --help | out-null -az boards --help | out-null -az repos --help | out-null -az artifacts --help | out-null - Write-Host "Warmup-User.ps1 - completed" From 82e0603292338d3e38686d59cb981abec3dd2e2c Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Tue, 19 Sep 2023 11:57:58 +0200 Subject: [PATCH 06/21] Switches '[int]` for `[uint]` on Windows PS5 --- .../scripts/ImageHelpers/InstallHelpers.ps1 | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 36d8363845b6..c6e22f550fe0 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -644,6 +644,43 @@ function Get-GitHubPackageDownloadUrl { return $downloadUrl } +function Invoke-ValidateCommand { + param( + [Parameter(Mandatory)] + [string]$Command, + [int] $Timeout = 0 + ) + + if ($Timeout -eq 0) + { + $output = Invoke-Expression -Command $Command + if ($LASTEXITCODE -ne 0) { + throw "Command '$Command' has finished with exit code $LASTEXITCODE" + } + return $output + } + else + { + $job = $command | Start-Job -ScriptBlock { + $output = Invoke-Expression -Command $input + if ($LASTEXITCODE -ne 0) { + throw 'Command failed' + } + return $output + } + $waitObject = $job | Wait-Job -Timeout $Timeout + if(-not $waitObject) + { + throw "Command '$Command' has timed out" + } + if($waitObject.State -eq 'Failed') + { + throw "Command '$Command' has failed" + } + Receive-Job -Job $job + } +} + function Use-ChecksumComparison { param ( [Parameter(Mandatory=$true)] From d8ff5a1019859148df8e35b9fd326cad5b26654d Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Wed, 20 Sep 2023 16:21:11 +0200 Subject: [PATCH 07/21] Suppresses warning about experimental status of `az config` --- images/win/scripts/Installers/Install-AzureCli.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index 70ae7d74c134..9779f4c6d4af 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -20,12 +20,12 @@ Set-SystemVariable -SystemVariable "AZURE_CONFIG_DIR" -value $azureCliConfigPath # Turn use automation recommended settings to speed up first-call on the hosted runner images. Write-Host "Setting automation defaults for 'az'" -Invoke-ValidateCommand -Command "az config set auto-upgrade.enable=false" -Invoke-ValidateCommand -Command "az config set core.error_recommendation=off" -Invoke-ValidateCommand -Command "az config set core.disable_progress_bar=true" -Invoke-ValidateCommand -Command "az config set core.no_color=true" -Invoke-ValidateCommand -Command "az config set logging.enable_log_file=no" -Invoke-ValidateCommand -Command "az config set output.show_survey_link=no" +Invoke-ValidateCommand -Command "az config set auto-upgrade.enable=false --only-show-errors" +Invoke-ValidateCommand -Command "az config set core.error_recommendation=off --only-show-errors" +Invoke-ValidateCommand -Command "az config set core.disable_progress_bar=true --only-show-errors" +Invoke-ValidateCommand -Command "az config set core.no_color=true --only-show-errors" +Invoke-ValidateCommand -Command "az config set logging.enable_log_file=no --only-show-errors" +Invoke-ValidateCommand -Command "az config set output.show_survey_link=no --only-show-errors" # Warm-up Azure CLI Write-Host "Warmup 'az'" From c1b3d6b2b565e19a809c6fcd820ba929e3c1e584 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Wed, 20 Sep 2023 16:23:28 +0200 Subject: [PATCH 08/21] Do not disable file logging for now. --- images/win/scripts/Installers/Install-AzureCli.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index 9779f4c6d4af..525b358c02d3 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -24,9 +24,12 @@ Invoke-ValidateCommand -Command "az config set auto-upgrade.enable=false --only- Invoke-ValidateCommand -Command "az config set core.error_recommendation=off --only-show-errors" Invoke-ValidateCommand -Command "az config set core.disable_progress_bar=true --only-show-errors" Invoke-ValidateCommand -Command "az config set core.no_color=true --only-show-errors" -Invoke-ValidateCommand -Command "az config set logging.enable_log_file=no --only-show-errors" Invoke-ValidateCommand -Command "az config set output.show_survey_link=no --only-show-errors" +# Though recommended by az init, this may be a breaking change. +# Invoke-ValidateCommand -Command "az config set logging.enable_log_file=no --only-show-errors" + + # Warm-up Azure CLI Write-Host "Warmup 'az'" Invoke-ValidateCommand -Command "az --help" From 0aacdc610e0bca3d99eca635925126c66a784465 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Wed, 20 Sep 2023 16:31:35 +0200 Subject: [PATCH 09/21] Update Install-AzureCli.ps1 --- images/win/scripts/Installers/Install-AzureCli.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index 525b358c02d3..36f1012aabe4 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -19,6 +19,8 @@ $null = New-Item -ItemType "Directory" -Path $azureCliConfigPath Set-SystemVariable -SystemVariable "AZURE_CONFIG_DIR" -value $azureCliConfigPath # Turn use automation recommended settings to speed up first-call on the hosted runner images. +# See: https://techcommunity.microsoft.com/t5/azure-tools-blog/streamline-configuring-azure-cli-with-az-init/ba-p/3051810 + Write-Host "Setting automation defaults for 'az'" Invoke-ValidateCommand -Command "az config set auto-upgrade.enable=false --only-show-errors" Invoke-ValidateCommand -Command "az config set core.error_recommendation=off --only-show-errors" From 3dd6743f5c01f5753dde728334e5d6b4d688797e Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Thu, 21 Sep 2023 19:35:12 +0200 Subject: [PATCH 10/21] Properly turns off survey messages See: https://github.com/Azure/azure-cli/issues/25242 --- images/win/scripts/Installers/Install-AzureCli.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index 36f1012aabe4..b25daeec58dc 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -26,7 +26,7 @@ Invoke-ValidateCommand -Command "az config set auto-upgrade.enable=false --only- Invoke-ValidateCommand -Command "az config set core.error_recommendation=off --only-show-errors" Invoke-ValidateCommand -Command "az config set core.disable_progress_bar=true --only-show-errors" Invoke-ValidateCommand -Command "az config set core.no_color=true --only-show-errors" -Invoke-ValidateCommand -Command "az config set output.show_survey_link=no --only-show-errors" +Invoke-ValidateCommand -Command "az config set core.survey_message=false --only-show-errors" # Though recommended by az init, this may be a breaking change. # Invoke-ValidateCommand -Command "az config set logging.enable_log_file=no --only-show-errors" From 8d92ec28c0ef8b068646f936438c43eaad38a3eb Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 11:13:12 +0200 Subject: [PATCH 11/21] Update Install-AzureCli.ps1 --- images/win/scripts/Installers/Install-AzureCli.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureCli.ps1 b/images/win/scripts/Installers/Install-AzureCli.ps1 index b25daeec58dc..041a6a5c2e1e 100644 --- a/images/win/scripts/Installers/Install-AzureCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureCli.ps1 @@ -11,12 +11,12 @@ Update-Path # Store cli extensions outside of the provisioning user's profile $azureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory' $null = New-Item -ItemType "Directory" -Path $azureCliExtensionPath -Set-SystemVariable -SystemVariable "AZURE_EXTENSION_DIR" -value $azureCliExtensionPath +$env:AZURE_EXTENSION_DIR = Set-SystemVariable -SystemVariable "AZURE_EXTENSION_DIR" -value $azureCliExtensionPath # Store cli config outside of the provisioning user's profile $azureCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureCliDirectory' $null = New-Item -ItemType "Directory" -Path $azureCliConfigPath -Set-SystemVariable -SystemVariable "AZURE_CONFIG_DIR" -value $azureCliConfigPath +$env:AZURE_CONFIG_DIR = Set-SystemVariable -SystemVariable "AZURE_CONFIG_DIR" -value $azureCliConfigPath # Turn use automation recommended settings to speed up first-call on the hosted runner images. # See: https://techcommunity.microsoft.com/t5/azure-tools-blog/streamline-configuring-azure-cli-with-az-init/ba-p/3051810 From b85a098669338e7244f6ef941b382e2e93e2deb6 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 11:13:49 +0200 Subject: [PATCH 12/21] Update Install-AzureDevOpsCli.ps1 --- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index 7236892e01d8..8e9095d2dc52 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -6,11 +6,11 @@ # Store azure-devops-cli cache outside of the provisioning user's profile $azureDevOpsCliConfigPath = Join-Path $Env:CommonProgramFiles 'AzureDevOpsCliConfigDirectory' $null = New-Item -ItemType "Directory" -Path $azureDevOpsCliConfigPath -Set-SystemVariable -SystemVariable "AZURE_DEVOPS_EXT_CONFIG_DIR" -value $azureDevOpsCliConfigPath +$env:AZURE_DEVOPS_EXT_CONFIG_DIR = Set-SystemVariable -SystemVariable "AZURE_DEVOPS_EXT_CONFIG_DIR" -value $azureDevOpsCliConfigPath $azureDevOpsCliCachePath = Join-Path $azureDevOpsCliConfigPath "cache" $null = New-Item -ItemType "Directory" -Path $azureDevOpsCliCachePath -Set-SystemVariable -SystemVariable "AZURE_DEVOPS_CACHE_DIR" -value $azureDevOpsCliCachePath +$env:AZURE_DEVOPS_CACHE_DIR = Set-SystemVariable -SystemVariable "AZURE_DEVOPS_CACHE_DIR" -value $azureDevOpsCliCachePath Invoke-ValidateCommand -Command "az extension add -n azure-devops" From 6ff129ba7eba82b6e69df1213bceebe8adac325c Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 14:24:27 +0200 Subject: [PATCH 13/21] Update Install-AzureDevOpsCli.ps1 --- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index 8e9095d2dc52..c36a9a5a9b2c 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -21,4 +21,8 @@ Write-Host "Warmup 'az-devops'" Invoke-ValidateCommand -Command "az $_ --help" } +# Run logout command to force installation of the python credential handlers +Invoke-ValidateCommand -Command "echo "dummy" | az devops login" +Invoke-ValidateCommand -Command "az devops logout" + Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" From 10eaf150ef575940a8070937e43938969c4e8588 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 14:38:00 +0200 Subject: [PATCH 14/21] fix quotes around dummy --- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index c36a9a5a9b2c..e35e42e2fb77 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -22,7 +22,7 @@ Write-Host "Warmup 'az-devops'" } # Run logout command to force installation of the python credential handlers -Invoke-ValidateCommand -Command "echo "dummy" | az devops login" +Invoke-ValidateCommand -Command "echo 'dummy' | az devops login" Invoke-ValidateCommand -Command "az devops logout" Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" From 67b4a8d3b9aac0e57105164267f19a5f41edd59e Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 14:50:38 +0200 Subject: [PATCH 15/21] Imrpoves comment --- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index e35e42e2fb77..14a54a72a943 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -21,7 +21,7 @@ Write-Host "Warmup 'az-devops'" Invoke-ValidateCommand -Command "az $_ --help" } -# Run logout command to force installation of the python credential handlers +# Run login/logout command to force installation of the python credential handlers Invoke-ValidateCommand -Command "echo 'dummy' | az devops login" Invoke-ValidateCommand -Command "az devops logout" From ad59f07ce552e746dd63f78c13b55cdedcd7a909 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 17:02:07 +0200 Subject: [PATCH 16/21] How did that `uint` sneak back in... --- images/win/scripts/ImageHelpers/InstallHelpers.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index c6e22f550fe0..9f767e1f4db1 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -728,7 +728,7 @@ function Get-HashFromGitHubReleaseBody { } } $body = (Invoke-RestMethod -Uri $releaseUrl).body -replace('`', "") -join "`n" - $matchingLine = $body.Split("`n") | Where-Object { $_ -like "*$FileName*" } + $matchingLine = $body.Split("`n") | Where-Object { $_ -like "*$FileName*" } if ([string]::IsNullOrEmpty($matchingLine)) { throw "File name '$FileName' not found in release body." } @@ -745,9 +745,9 @@ function Test-FileSignature { [Parameter(Mandatory=$true)] [string]$ExpectedThumbprint ) - + $signature = Get-AuthenticodeSignature $FilePath - + if ($signature.Status -ne "Valid") { throw "Signature status is not valid. Status: $($signature.Status)" } @@ -763,7 +763,7 @@ function Invoke-ValidateCommand { param( [Parameter(Mandatory)] [string]$Command, - [Uint] $Timeout = 0 + [int] $Timeout = 0 ) if ($Timeout -eq 0) From 7900076d8ca562289169473a59c2a61300b436c3 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 19:30:50 +0200 Subject: [PATCH 17/21] Update Install-AzureDevOpsCli.ps1 --- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index 14a54a72a943..ae1c72475d69 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -21,8 +21,8 @@ Write-Host "Warmup 'az-devops'" Invoke-ValidateCommand -Command "az $_ --help" } -# Run login/logout command to force installation of the python credential handlers -Invoke-ValidateCommand -Command "echo 'dummy' | az devops login" -Invoke-ValidateCommand -Command "az devops logout" +# az devops login requires python package 'keyring~=17.1.1' unfortunately it won't install +# when az devops is running in a non-interactive session by calling `az devops login` +Invoke-ValidateCommand -Command "'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe' -m pip install keyring~=17.1.1 --target '$env:AZURE_EXTENSION_DIR\azure-devops' -vv --disable-pip-version-check --no-cache-dir" Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" From 129a955a58bee1d46d88a5c44c442ab6ead4e353 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 19:53:53 +0200 Subject: [PATCH 18/21] Find python from the path of `az` --- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index ae1c72475d69..ee0a5a6aba41 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -23,6 +23,7 @@ Write-Host "Warmup 'az-devops'" # az devops login requires python package 'keyring~=17.1.1' unfortunately it won't install # when az devops is running in a non-interactive session by calling `az devops login` -Invoke-ValidateCommand -Command "'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe' -m pip install keyring~=17.1.1 --target '$env:AZURE_EXTENSION_DIR\azure-devops' -vv --disable-pip-version-check --no-cache-dir" +$pythonPath = resolve-path (join-path ([System.IO.Path]::GetDirectoryName((Get-Command az).Path)) "..\python.exe") +Invoke-ValidateCommand -Command "& '$pythonPath' -m pip install keyring~=17.1.1 --target '$env:AZURE_EXTENSION_DIR\azure-devops' -vv --disable-pip-version-check --no-cache-dir" Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" From a67e88331e97c5a3134358c5dbaafb84e08f5f81 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 20:13:21 +0200 Subject: [PATCH 19/21] And lets try ignoring the error to see what happens. --- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index ee0a5a6aba41..b3b6af83b55d 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -23,7 +23,7 @@ Write-Host "Warmup 'az-devops'" # az devops login requires python package 'keyring~=17.1.1' unfortunately it won't install # when az devops is running in a non-interactive session by calling `az devops login` -$pythonPath = resolve-path (join-path ([System.IO.Path]::GetDirectoryName((Get-Command az).Path)) "..\python.exe") -Invoke-ValidateCommand -Command "& '$pythonPath' -m pip install keyring~=17.1.1 --target '$env:AZURE_EXTENSION_DIR\azure-devops' -vv --disable-pip-version-check --no-cache-dir" +echo "dummy" | az devops login --debug +az devops logout --debug Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" From 03dc291121505d71668f855dd0ff46d2fa8b88ca Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 22 Sep 2023 22:30:41 +0200 Subject: [PATCH 20/21] Update Install-AzureDevOpsCli.ps1 --- images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 index b3b6af83b55d..dba020109999 100644 --- a/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 +++ b/images/win/scripts/Installers/Install-AzureDevOpsCli.ps1 @@ -21,9 +21,9 @@ Write-Host "Warmup 'az-devops'" Invoke-ValidateCommand -Command "az $_ --help" } -# az devops login requires python package 'keyring~=17.1.1' unfortunately it won't install -# when az devops is running in a non-interactive session by calling `az devops login` -echo "dummy" | az devops login --debug -az devops logout --debug +# calling az devops login to force it to install `keyring`. Login will actually fail, redirecting error to null +echo "dummy" | az devops login | out-null +# calling az devops logout to be sure no credentials remain. +az devops logout | out-null Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Azure DevOps CLI" From e38336b2d61ab2bd79eabd1d7726a200e505bda6 Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Fri, 29 Sep 2023 10:15:58 +0200 Subject: [PATCH 21/21] Update images/win/scripts/ImageHelpers/PathHelpers.ps1 Co-authored-by: Stijn Devogel <38946188+StijnDevogel@users.noreply.github.com> --- images/win/scripts/ImageHelpers/PathHelpers.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/ImageHelpers/PathHelpers.ps1 b/images/win/scripts/ImageHelpers/PathHelpers.ps1 index 7459241810f3..8a677e6ee37c 100644 --- a/images/win/scripts/ImageHelpers/PathHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/PathHelpers.ps1 @@ -38,7 +38,7 @@ function Get-UserVariable { [string]$UserVariable ) - [System.Environment]::GetEnvironmentVariable($SystemVariable, "User") + [System.Environment]::GetEnvironmentVariable($UserVariable, "User") } function Get-SystemVariable {