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

exit on error #8

Open
agsmorodin opened this issue Sep 4, 2015 · 3 comments
Open

exit on error #8

agsmorodin opened this issue Sep 4, 2015 · 3 comments

Comments

@agsmorodin
Copy link

Is it possible to interrupt the script execution if something went wrong?
I can achieve it by using 'set -e' at the begging of the script, but in this case I need to set this flag for all my scripts. Is there any way to setup it globally? or to pass to /bin/sh specific flag from gocd?

@srinivasupadhya
Copy link
Collaborator

I will see what I can do for this. But since you already have a workaround its not a priority.

@Hraesvelg
Copy link

i up this request...

i would like to have a failed if my script exit(1) ... all values != 0 -> failed
if script return 0 -> success

@chadlwilson
Copy link
Contributor

chadlwilson commented Jul 8, 2024

@Hraesvelg It should already work the way you describe if you use explicit exit codes/calls from a non Windows shell.

int exitCode = executeScript(workingDirectory, shType, scriptFileName, isWindows, environmentVariables);
if (exitCode == 0) {
response.put("success", true);
response.put("message", "[script-executor] Script completed successfully.");
} else {
response.put("success", false);
response.put("message", "[script-executor] Script completed with exit code: " + exitCode + ".");
}

This ticket is about exiting early if any of the commands within the script exit with non-zero exit code, i.e exiting early.

Implementing the original request across shells is possible but a bit of a rabbithole, as even with bash/zsh you need set -euo pipefail to get canonical behaviour across arbitrary scripts (with -u being opinionated but good practice to give people the semantics they normally expect), painful variations for csh and to my knowledge no equivalent of pipefail for POSIX shell just yet...

But yeah, could possibly just drop csh these days and allow opt-in for -euo pipefail on sh in case folks are using, for eg Alpine/Busybox shell.

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

No branches or pull requests

4 participants