navcontainerhelper
navcontainerhelper copied to clipboard
Install/Upgrade Azure CLI not working on Install-AzDevop
Describe the issue I'm having troubles to get the Install-AzDevop working on both (install and upgrade) scenario's. I'll start on the upgrade scenario first.
B) Upgrade When running the Install-AzDevop on a machine where Azure CLI is installed, it isn't upgraded.
Scripts used to create container and cause the issue
Import-Module BcContainerHelper -DisableNameChecking
Install-AzDevops
$az_upgrade = Write-Output n | az upgrade 2>&1
$az_upgrade | Select-String "Latest version available"
Write-Host $az_upgrade
Full output of scripts
Import-Module BcContainerHelper -DisableNameChecking
Install-AzDevops
$az_upgrade = Write-Output n | az upgrade 2>&1
$az_upgrade | Select-String "Latest version available"
Write-Host $az_upgrade
WARNING: Your current Azure CLI version is 2.42.0. Latest version available is 2.49.0.
WARNING: This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus WARNING: Your current Azure CL
I version is 2.42.0. Latest version available is 2.49.0. WARNING: Please check the release notes first: https://docs.microsoft.com/cli/azure/release
-notes-azure-cli ERROR: No tty available. Please run command with --yes.
I would expect the version to be upgraded from 2.42.0 to 2.49.0.
A) Install When running the Install-AzDevop on a machine where Azure CLI isn't installed it throws an error.
Scripts used to create container and cause the issue
Import-Module BcContainerHelper -DisableNameChecking
Install-AzDevops
Full output of scripts
Install-AzDevops Telemetry Correlation Id: f380d4b0-8936-4162-ae4b-a2b44a2daab1
az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\5.0.3\PackageHandling\Install-AzDevops.ps1:23 char:19
+ $extensions = az extension list -o json | ConvertFrom-Json
+ ~~
+ CategoryInfo : ObjectNotFound: (az:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
...
In the Install-scenario I'm doubting if there's possible a (second) bug preventing the install of az cli. The description of the functions shows If az cli is installed, an update will be done. Otherwise the installation will be performed.
, so I would expect the result that az cli is going to be installed if not present.
Try {
$az_upgrade = Write-Output n | az upgrade 2>&1
} catch {
$az_upgrade = ""
}
When az cli is installed, the $az_upgrade
param is populated with something like WARNING: Your current Azure CLI version is 2.42.0. Latest version available is 2.49.0.
. When az cli is not installed, the catch wil set this variable to blank.
if (@($az_upgrade | Select-String "Latest version available").Count -ne 0) {
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
}
The if statement hereafter returns a zero on the case az cli is not installed, where the if stament is only executed if the count not equals zero. So the the line for installing az cli isn't executed?
@jonaswre - do you know anything about this?
I'll add some comments to the code just to clear things up.
Try {
// This is only used to figure out if an update is needed.
// This is not actually doing the updating. Because this won't do the install quiet in the background.
// This will open the installer so you need to press next/continue/finish which is not desired in no gui enviroments.
// The Write-Output is to suppose to anwser "No" to the question if you want to install it.
$az_upgrade = Write-Output n | az upgrade 2>&1
} catch {
// This should probaly be $az_upgrade = "Latest version available" because in case that az wasn't found a fresh install should be done.
$az_upgrade = ""
}
// This checks if a installed should be done.
if (@($az_upgrade | Select-String "Latest version available").Count -ne 0) {
//This is doing a quiet install.
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
}
$extensions = az extension list -o json | ConvertFrom-Json
$devopsFound = $False
foreach($extension in $extensions)
{
if($extension.name -eq 'azure-devops'){
$devopsFound = $True
}
}
if ($devopsFound -eq $False){
az extension add -n azure-devops
}
Will create a PR to fix the $az_upgrade = ""
line which prevents the install
@Arthurvdv has this solved your issue?
@jonaswre, thanks for looking into this, really appreciatie it.
The upgrade part is working as expected, but I still seems to have troubles on a machine where Azure CLI isn't already installed.