Skip to content
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

The Azure CLI Task does not fail when a command fails #10125

Closed
jlorich opened this issue Apr 15, 2019 · 9 comments
Closed

The Azure CLI Task does not fail when a command fails #10125

jlorich opened this issue Apr 15, 2019 · 9 comments

Comments

@jlorich
Copy link

jlorich commented Apr 15, 2019

Required Information

Type: Bug
Task Name: Azure CLI

Environment

Server: Azure Pipelines
Account Name: mtcdenver
Project Name: Azure Demos
Build Definition Name: demo-whack-a-mole-admin
Build Number: #20190401.2
Agent: Hosted

Issue Description

When a command within the Azure CLI task fails, subsequent commands within the script continue to run and the task is marked as successful, causing the build or release process to conitnue. The Azure CLI task only fails if there is a failing exit code on the last command, which is not how any script runner should be expected to work.

Any failing exit code returned from any command should immediately terminate the script and mark the task as failed.

Task logs

Relevant log snippet:

2019-04-01T23:40:40.9454429Z /bin/sh: 1: slkjdflsdkjfsd: not found
2019-04-01T23:40:40.9455322Z The command '/bin/sh -c slkjdflsdkjfsd' returned a non-zero code: 127
2019-04-01T23:40:40.9455855Z 2019/04/01 23:40:39 Container failed during run: build. No retries remaining.
2019-04-01T23:40:40.9456310Z failed to run step ID: build: exit status 127
2019-04-01T23:40:40.9456648Z 
2019-04-01T23:40:40.9457059Z Run ID: cj1t failed after 1m25s
2019-04-01T23:40:40.9671327Z ERROR: Run failed

However the task continues to run other commands after, and marks itself as successful.

Full Debug Logs

@ghost ghost added route triage labels Apr 15, 2019
@cwiederspan
Copy link

We have run into this issue with a customer project that looking to bring a large Heroku app into Azure and Azure DevOps. Would be great if this script worked like many/most of the others out there.

@jlorich
Copy link
Author

jlorich commented Apr 15, 2019

I often recommend use of the Azure CLI task to build and push containers as well, as it's nice to be able to interact with ACR without creating a seperate service principal. However with how things are designed now I need an incredibly over complicated script to check each previous lines success and only continue if it's really working.

@amaljg
Copy link
Member

amaljg commented Apr 17, 2019

@jlorich @cwiederspan The Azure CLI task relies on the scripting environment’s behaviour. For inline scripts, the task actually creates a batch script (in Windows) or bash script (in Linux) with the specified commands and executes the script. So the behaviour of whether to exit on individual command failure or not is dependent on the script & scripting environment. The default behaviour for batch script (Windows) is to exit on failure, while the same for bash script (Linux) is to continue irrespective of return code.

@jlorich Since you are running the script on Ubuntu agent, your script is simply continuing further without considering the return code of individual commands. If you want to alter this behaviour, you need to modify your script appropriately – either explicitly check for command return code for specific commands or alter the script execution behaviour. E.g., in order to achieve the latter in Ubuntu, you can probably add “set -e” command to the start of your script.

Let us know if this doesn't work for you.

@jlorich
Copy link
Author

jlorich commented Apr 17, 2019

Thanks for the insights @amaljg. Perhaps this is just a lacking in the documentation then, as both myself and a number of others have ran into this in the past - especially with inconsistencies depending on the agent that is running. I think this has led to a number of various issues that have been filed here in the past too. For an external script file, setting set -e makes sense, for an inline script to me that was already the expected behavior. It gets especially confusing since there are "fail on standard error" and "continue on error" options in the GUI, but neither really perform what I feel the general expectation would be.

To me having adding an option that sets set -e for you, and tweaking the option descriptions may help prevent this confusion in the future. For example, if the options were:

  • Fail task immediately if a command fails
  • Fail task after script execution on StandardError

This would make it quite clear what is happening, and also provide the option to write a release task that is not dependent on the underlying agents behavior.

@amaljg
Copy link
Member

amaljg commented Apr 22, 2019

Thanks @jlorich for the feedback. Adding @pulkitaggarwl to consider the feedback in the next version of the task. For now, since you are unblocked, I'm closing this issue. Feel free to reach out to us, if you need any further help.

@amaljg amaljg closed this as completed Apr 22, 2019
jgraham pushed a commit to web-platform-tests/wpt that referenced this issue Feb 4, 2021
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Feb 9, 2021
…d fail the run, a=testonly

Automatic update from web-platform-tests
Fix #27476: Installing STP failing should fail the run

NB: microsoft/azure-pipelines-tasks#10125

--

wpt-commits: 84b2f829080ddd13feabe98d68ce3fddbcf543c4
wpt-pr: 27477
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Feb 10, 2021
…d fail the run, a=testonly

Automatic update from web-platform-tests
Fix #27476: Installing STP failing should fail the run

NB: microsoft/azure-pipelines-tasks#10125

--

wpt-commits: 84b2f829080ddd13feabe98d68ce3fddbcf543c4
wpt-pr: 27477

UltraBlame original commit: a7a3846e593c00be847c844404fdae07c53cae39
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Feb 10, 2021
…d fail the run, a=testonly

Automatic update from web-platform-tests
Fix #27476: Installing STP failing should fail the run

NB: microsoft/azure-pipelines-tasks#10125

--

wpt-commits: 84b2f829080ddd13feabe98d68ce3fddbcf543c4
wpt-pr: 27477

UltraBlame original commit: a7a3846e593c00be847c844404fdae07c53cae39
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Feb 10, 2021
…d fail the run, a=testonly

Automatic update from web-platform-tests
Fix #27476: Installing STP failing should fail the run

NB: microsoft/azure-pipelines-tasks#10125

--

wpt-commits: 84b2f829080ddd13feabe98d68ce3fddbcf543c4
wpt-pr: 27477

UltraBlame original commit: a7a3846e593c00be847c844404fdae07c53cae39
@flying-sheep
Copy link

Since I see no open feature request: Is there an option now? Will we get one?

It’s easy to forget to add set -e for every single CLI task, it would be great to set it globally once.

jamienicol pushed a commit to jamienicol/gecko that referenced this issue Feb 11, 2021
…d fail the run, a=testonly

Automatic update from web-platform-tests
Fix #27476: Installing STP failing should fail the run

NB: microsoft/azure-pipelines-tasks#10125

--

wpt-commits: 84b2f829080ddd13feabe98d68ce3fddbcf543c4
wpt-pr: 27477
@stodirascu
Copy link

stodirascu commented Sep 12, 2022

I believe the setting is there already, called failOnStderr

@kappmeier
Copy link

@stodirascu that does not sound correct. failOnStderr lets a task fail when there is any output on the error stream, there is no check whether or not the output of a command is 0 (or any failure).

@stodirascu
Copy link

Aha, I see, @kappmeier. Then +1 for this to be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants