Skip to content

shell_commands should fail immediately if one of the commands fails#957

Merged
philwo merged 1 commit intobazelbuild:masterfrom
mostynb:shell_commands_set_e
Mar 17, 2020
Merged

shell_commands should fail immediately if one of the commands fails#957
philwo merged 1 commit intobazelbuild:masterfrom
mostynb:shell_commands_set_e

Conversation

@mostynb
Copy link
Copy Markdown
Contributor

@mostynb mostynb commented Mar 3, 2020

It seems that shell_commands are joined with newlines and then run in a single subprocess.run call, in which case the return value is that of the last command- any failures in previous commands are ignored.

Users probably expect such failures to cause the entire build to fail. Changing this behaviour feels like the right thing to do, even though it may cause some projects to fail CI until the corresponding errors are fixed.

By prepending "set -e" to the shell commands, the shell will exit immediately with an error code when a command fails (apart from some special cases like if conditions or commands followed by ||).

This might fix #938 for linux/mac.

It seems that shell_commands are joined with newlines and then run in
a single subprocess.run call, in which case the return value is that
of the last command- any failures in previous commands are ignored.

Users probably expect such failures to cause the entire build to fail.
Changing this behaviour feels like the right thing to do, even though
it may cause some projects to fail CI until the corresponding errors
are fixed.

By prepending "set -e" to the shell commands, the shell will exit
immediately with an error code when a command fails (apart from some
special cases like if conditions or commands followed by ||).

This might fix bazelbuild#938 for linux/mac.
@mostynb mostynb requested review from fweikert and philwo as code owners March 3, 2020 23:53
mostynb added a commit to mostynb/remote-apis-sdks that referenced this pull request Mar 5, 2020
ola-rozenfeld pushed a commit to bazelbuild/remote-apis-sdks that referenced this pull request Mar 16, 2020
* presubmit: shell_commands should exit if any command fails

This may not be needed if this bazelci PR lands:
bazelbuild/continuous-integration#957

* presubmit: use consistent indentation
Copy link
Copy Markdown
Member

@philwo philwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Seems reasonable to me.

@philwo philwo merged commit 1444091 into bazelbuild:master Mar 17, 2020
@mostynb mostynb deleted the shell_commands_set_e branch March 17, 2020 22:09
philwo added a commit to bazelbuild/remote-apis-sdks that referenced this pull request Mar 19, 2020
ifoox pushed a commit to bazelbuild/remote-apis-sdks that referenced this pull request Mar 19, 2020
pl4nty pushed a commit to pl4nty/remote-apis-sdks that referenced this pull request Apr 18, 2025
…d#127)

* presubmit: shell_commands should exit if any command fails

This may not be needed if this bazelci PR lands:
bazelbuild/continuous-integration#957

* presubmit: use consistent indentation
pl4nty pushed a commit to pl4nty/remote-apis-sdks that referenced this pull request Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

only the last entry in shell_commands can fail the build

2 participants