-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AZ CLI 2.40 on Windows Powershell fails to run '&' invocation operator with parameters #23890
Comments
@jiasli for awareness |
I think I have the same issue and it is affecting our ability to use the call operator and mock az using pester for testing, for example: Describe "mocking az" {
It "mock az" {
function GetAzVersion {
& az version
}
Mock az { Write-Warning "$args"; Write-Output "az successfully mocked" }
GetAzVersion | Should -Be "az successfully mocked"
Should -Invoke az -Exactly -Times 1 -ParameterFilter { $args[0] -eq 'version' }
}
} The expected behaviour is for the tests to pass as the az command was not invoked but the mock was.
|
In my own wording: In az 2.39 the following was still possible:
In az 2.40 this breaks: With Az cli 2.39
With Az cli 2.40
Workaround found, with az 2.40: pwsh -command az @("extension", "list") works. Permanent solutionInside |
This can be solved by adapting the build_scripts/windows/scripts/az.ps1 script: $env:AZ_INSTALLER="MSI"
& "$PSScriptRoot\..\python.exe" -IBm azure.cli $args
# SIG # Begin signature block
# <generated signature omitted> should become $env:AZ_INSTALLER="MSI"
& "$PSScriptRoot\..\python.exe" -IBm azure.cli @args # notice the @ instead of the $ here with @args
# SIG # Begin signature block
# <generated signature omitted> Maintainers should re-generate the signature block ofcourse. So I won't be offering a pull request at this time. This can be used as a local work-around too. Just change Thanks @cveld for drawing my attention to this issue :-) |
We are encountering the same/very similar issue in a script that is bundled with our project, and customers are now unable to login if using $loginArgs = @();
$loginArgs += @("--username=""exampleusername""");
$loginArgs += @("--password=""examplepassword""");
$loginArgs += @("--tenant=""exampletenant""");
az login --service-principal $loginArgs This runs in a non-interactive PowerShell session, and so just appears to hang indefinitely for the user. When run in an interactive session, you get the |
This has had me fixing infrastructure code on so many release branches in different repositories. Please, for the love of all that is good. Fix this issue with 2.41 so I don't have to go and fix even more stuff when it inevitably breaks on an older branch of mine which needs hotfixing. |
Thank you for your feedback. This has been routed to the support team for assistance. |
The next version will revert that change and will be shipped on 10.12 |
@yonzhan will this be done in such a way that the workaround mentioned in this thread will still work? So both these snippets would perform the same:
and
Example courtesy of @Jawz84 |
If 2.39 works, 2.41 works. |
Thank you for taking this up and informing us. |
Duplicate of #23797 |
@cveld, This can be verified with: test.ps1: $args.GetType()
$args[0].GetType()
$args[0][0].GetType()
|
Related command
Any AZ command with arguments using an invocation operator.
Describe the bug
In PowerShell on Windows, with CLI 2.40, using PS 5.2, 7.2.6 or 7.3.preview7, all versions fail to run script blocks with the invocation (call) operator '&' and passing an arguments array. It looks like parsing is not done correctly and could be linked to this article https://github.com/Azure/azure-cli/blob/dev/doc/quoting-issues-with-powershell.md
To Reproduce
Try out a block like this in your PowerShell terminal, the result is Azure CLI returning an error that the 'account show' is misspelled or cmdlet not found.
Expected behavior
The expected behavior is that 'az account show' should be executed and the result of the JSON shown on screen.
Environment summary
OS: Windows 11 insider build
PowerShell 7.2.6
AZ CLI: 2.40
I also tested this on PowerShell in CloudShell and there it runs as expected. Als on PowerShell on Linux WSL2 it works fine, both using Azure CLI 2.40. It seems the issue is only arising on Windows.
The text was updated successfully, but these errors were encountered: