azure-cli: Writing to `stderr` causes failure on pipeline tasks with `failOnStderr` set to `true`

Describe the bug We have been noticing the following warning after upgrading from Az Cli 2.0.73 to 2.24 in our pipeline operation for purging AFD cache. It is causing the pipeline to fail. The operation depends on an extension of Az Cli called “front-door”, although I have tried reverting the extension to original version (1.0.2) and the warning still persists.

Can you please help us identify if this is something related to the pipeline agent itself or Az Cli? It looks like doing some telemetry check. Also, I don’t see this kind of check when I test the operation locally on my devbox with --debug flag.

image

To Reproduce Run

az network front-door purge-endpoint --resource-group <RG-NAME> --name <NAME> --content-paths /* --debug

Expected behavior No warnings.

Environment summary Az Cli version: 2.24 front-door extension version: 1.0.14, 1.0.2 Pipeline agent pools are running Windows_NT

Additional context Link to error message within a pipeline failure: Link

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Warning type output for warnings, rather than error type, seems so much more logical here… while it could be concieve as “diagnostics”… the use of diagnostics in that context of the documentation is meant to be diagnostics issued by the program in regards to an error… not general diagnostics.

(Copied from https://github.com/Azure/azure-cli/issues/19314#issuecomment-917784104)

According to https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html

Variable: FILE * stderr The standard error stream, which is used for error messages and diagnostics issued by the program.

Therefore, stderr is the right place for Azure CLI to write WARNING messages.

If the pipeline has failOnStderr set to true and the WARNING message is causing failure, you may either

  1. In the pipeline, set failOnStderr to false.
  2. Disable WARNING messages in Azure CLI commands using the --only-show-errors flag or only_show_errors config option: https://learn.microsoft.com/en-us/cli/azure/azure-cli-configuration#cli-configuration-values-and-environment-variables

failOnStderr: true means as long as there is something printed to stderr, the pipeline fails:

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/bash?view=azure-devops#arguments

failOnStderr Fail on standard error (Optional) If this is true, this task will fail if any errors are written to stderr. Default value: false

It doesn’t distinguish whether the log message is DEBUG, INFO, WARNING, ERROR. These are Azure CLI’s own classification.

If you want to use --debug which prints all log messages to stderr, failOnStderr must be set to false. In other words, --debug and failOnStderr are mutually exclusive.

The correct way to detect if a CLI command fails is to check the exit code. In Bash, you can utilize set -e which automatically fails the script when a CLI command fails:

https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

-e Exit immediately if a pipeline (see Pipelines), which may consist of a single simple command (see Simple Commands), a list (see Lists), or a compound command (see Compound Commands) returns a non-zero status.

@rajarshi-singh , the pipeline link you shared is not available. Also the warning seems related to azure CLI telemetry upload and not related to Azure Front Door extension: https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-telemetry/azure/cli/telemetry/util.py#L35-L37 image

I am not sure whether this should be treated as a warning or not, @yonzhan could provide more details for that.

Anyway, if the warning is really an issue, you might consider to disable the telemetry collecting with:az configure -d collect_telemetry=false according to azure-cli-configuration