az cli version 2.0.74 commands write to stderr stream even when the command succeeds
az feedbackauto-generates most of the information requested below, as of CLI version 2.0.62
We own the "Azure CLI" Azure Pipelines task. We have come across 3 customer issues so far where az cli version 2.0.74 commands write to stderr stream even when the command succeeds Could be happening since some other older version, I don't know about that, but see this issue with at least this version.
Describe the bug We have come across 3 customer issues so far where az cli version 2.0.74 commands write to stderr stream even when the command succeeds At line:1 char:1
- az extension add --name application-insights --output none 2>&1
-
+ CategoryInfo : NotSpecified: (WARNING: Extens...eady installed.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError
To Reproduce For example, az extension add --name application-insights --output none 2>&1
Expected behavior successful commands should not write to stderr stream
Environment summary Azure Pipelines Hosted Agent, Powershell on my local machine
Additional context Add any other context about the problem here.
Hi, We have experienced this issue as well.
But according to the reply from this comment (https://github.com/Azure/azure-cli/issues/9891#issuecomment-539316006), this is the expected behavior.
So, what is the right approach? IMO, the error stream should not contain any garbage that is not really related to errors happened during the execution.
@jiasli please take a look.
It is by-design to write warnings to stderr. To remove the warning, on Windows use
az extension add --name application-insights --output none 2>nul
On Linux use
az extension add --name application-insights --output none 2>/dev/null
@jiasli using Azure DevOps pipelines to execute scripts it is common to turn on "Fail on Standard Error" because commands don't always exit with a non-zero value. Having Azure CLI commands output non-fatal errors to stderr makes it much more difficult to capture actual errors from CLI commands while still dealing with other script elements that don't behave nicely in other ways.
Can we close this issue?
@tvanfosson if you see any az command that returns zero value when it fails, please let us know. We will consider adding --no-warning or --quite switch in the future.
@jiasli we don't limit ourselves to just Azure CLI commands in our scripts. It's hard to definitely say that we can rely on command exit values only.
@jiasli
It is by-design to write warnings to stderr. To remove the warning, on Windows use
az extension add --name application-insights --output none 2>nul
This didn't work for me. Appending 2>null to --output none results in the following output:
out-file : FileStream was asked to open a device that was not a file. For support for devices like 'com1:' or 'lpt1:',
call CreateFile, then use the FileStream constructors that take an OS handle as an IntPtr.
At D:\a\1\s\automation\CreateTeam.ps1:120 char:13
+ $updateDenyPermissions = az devops security permission up ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], NotSupportedException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
For PowerShell, please use $null as the destination of the redirection:
az extension add --name application-insights --output none 2>$null
That fixed it, thanks.
We have added option --only-show-errors in #12604 to disable warnings that are written to stderr. It will be included in S167 release.
-bash: $null: ambiguous redirect getting this error, after using 2>$null
@Rajuvimal $null is for PowerShell. On bash use 2>/dev/null