And subsequent runs of az account show and az account list also work as expected. It seems like there is an issue with the az cli config and login context.
There is a difference of behavior between Windows and Ubuntu when it comes to the AzureCLI@2 task and the az cli command line.
Windows (fails)
knack.util.CLIError: Please run 'az login' to setup account.
Ubuntu (works)
[2024-07-16T09:27:14.3542439Z T: 140439931482368] INFO : Identity: DefaultAzureCredential: Successfully got token from AzureCliCredential. This credential will be reused for subsequent calls.
1) The CI machine images have different settings. On Windows, AZURE_CONFIG_DIR env var is set to C:\azureCli, whereas on Ubuntu that env var isn’t set. The fact that this env var is set on Windows is preventing az cli from getting the login context.
2) I am not sure how useGlobalConfig is supposed to work to make sure the machine and the az cli task all use the same login context on Windows. It seems like when that is set to false (default), the azure-pipelines-task sets the AZURE_CONFIG_DIR env var to a temp directory.
https://github.com/microsoft/azure-pipelines-tasks/blob/1e374b1730e8d81a6ba2e733048fa061b410a642/Tasks/AzureCLIV2/azureclitask.ts#L247-L259
3) For az cli to work as expected on Ubuntu, the cli task needs useGlobalConfig:true (which results in AZURE_CONFIG_DIR not being present at all). On Windows, whether useGlobalConfig is set or not, az account get-access-token ... fails with the az login error ("ERROR: Please run 'az login' to setup account.”).
From the table below, the only scenario that works as expected is green. I can’t get Windows to be green regardless of setting.
I got Ubuntu to work (with useGlobalConfig: true), but can't get Windows to work with any setting.
useGlobalConfig:true
useGlobalConfig:false
Windows
AZURE_CONFIG_DIR is set to C:\azureCli
AZURE_CONFIG_DIR is set to D:\a\_work\_temp\.azclitask
Ubuntu
AZURE_CONFIG_DIR is not present (i.e. not set to anything)
AZURE_CONFIG_DIR is set to mnt/vss/_work/_temp/.azclitask
Only when useGlobalConfig:true does manually setting AZURE_CONFIG_DIR take effect. Trying to set it to some value, as per the documentation, to isolate the az cli config and context, doesn’t work. With useGlobalConfig:false, manually setting AZURE_CONFIG_DIR is ignored. I don’t understand this behavior and it doesn’t seem to be documented anywhere.
I am not sure why az cli fails and is unable to honor the useGlobalConfig:true flag on Windows. I also don’t know how to unset the AZURE_CONFIG_DIR prior to the AzureCLI@2 task starts in the yaml (to match the behavior I am seeing on Ubuntu), nor whether that would bring parity of behavior between Ubuntu/Windows. Setting it to an empty string ('') causes the AzDo task to fail since that isn’t a valid path value.
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''
New issue checklist
Task name
AzureCLI
Task version
2
Issue Description
From https://github.com/Azure/azure-sdk-for-cpp/pull/5800 The az cli and AzureCliCredential work as expected on Ubuntu, but the same sample and
az account get-access-token
command fails on Windows, with an error asking to re-runaz login
.However, the cli task already successfully ran az login:
And subsequent runs of
az account show
andaz account list
also work as expected. It seems like there is an issue with the az cli config and login context.There is a difference of behavior between Windows and Ubuntu when it comes to the AzureCLI@2 task and the az cli command line.
Windows (fails)
Ubuntu (works)
1) The CI machine images have different settings. On Windows, AZURE_CONFIG_DIR env var is set to C:\azureCli, whereas on Ubuntu that env var isn’t set. The fact that this env var is set on Windows is preventing az cli from getting the login context. 2) I am not sure how
useGlobalConfig
is supposed to work to make sure the machine and the az cli task all use the same login context on Windows. It seems like when that is set to false (default), the azure-pipelines-task sets theAZURE_CONFIG_DIR
env var to a temp directory. https://github.com/microsoft/azure-pipelines-tasks/blob/1e374b1730e8d81a6ba2e733048fa061b410a642/Tasks/AzureCLIV2/azureclitask.ts#L247-L259 3) For az cli to work as expected on Ubuntu, the cli task needsuseGlobalConfig:true
(which results inAZURE_CONFIG_DIR
not being present at all). On Windows, whetheruseGlobalConfig
is set or not,az account get-access-token ...
fails with the az login error ("ERROR: Please run 'az login' to setup account.”). From the table below, the only scenario that works as expected is green. I can’t get Windows to be green regardless of setting.C:\azureCli
D:\a\_work\_temp\.azclitask
mnt/vss/_work/_temp/.azclitask
Only when
useGlobalConfig:true
does manually setting AZURE_CONFIG_DIR take effect. Trying to set it to some value, as per the documentation, to isolate the az cli config and context, doesn’t work. WithuseGlobalConfig:false
, manually settingAZURE_CONFIG_DIR
is ignored. I don’t understand this behavior and it doesn’t seem to be documented anywhere.I am not sure why az cli fails and is unable to honor the
useGlobalConfig:true
flag on Windows. I also don’t know how to unset theAZURE_CONFIG_DIR
prior to theAzureCLI@2
task starts in the yaml (to match the behavior I am seeing on Ubuntu), nor whether that would bring parity of behavior between Ubuntu/Windows. Setting it to an empty string ('') causes the AzDo task to fail since that isn’t a valid path value.Image Version: https://github.com/actions/runner-images/blob/win19/20240707.1/images/windows/Windows2019-Readme.md
C++ sample being run: https://github.com/ahsonkhan/azure-sdk-for-cpp/blob/4f087568210ba32878d58e26a7dbb7b9eebdb2b7/sdk/keyvault/azure-security-keyvault-keys/samples/sample1-hello-world/sample1_hello_world.cpp#L27
This is the task: https://github.com/ahsonkhan/azure-sdk-for-cpp/blob/4f087568210ba32878d58e26a7dbb7b9eebdb2b7/eng/pipelines/templates/jobs/live.tests.yml#L247C5-L287C49
Environment type (Please select at least one enviroment where you face this issue)
Azure DevOps Server type
dev.azure.com (formerly visualstudio.com)
Azure DevOps Server Version (if applicable)
Version: 20240707.1.0
Operation system
Windows 2019, Windows 2022, Ubuntu 20.04
Relevant log output
Full task logs with system.debug enabled
No response
Repro steps
Related issue: https://github.com/actions/runner-images/issues/10246