-
Notifications
You must be signed in to change notification settings - Fork 12
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
how to use exit codes #159
base: master
Are you sure you want to change the base?
Conversation
There are, however, times when a commands exit code provides important information. In those cases, we have two ways to work with exit codes. | ||
|
||
== Stop on errors | ||
The first option is to enable exit code checking with either the `-x` ro `--exitCode` command line argument or adding `check-exit-code` to the `settings`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
|
||
== Specific exit values | ||
|
||
qDup has built in support for zero and non-zero exit codes but a command can return any valid integer as an exit code and some commands provide error information based on the exit number. qDup does not have native support for filtering the exit code but we can add `echo $?` to our scripts the same way we would check the exit code if we were manually runnin commands in an ssh terminal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
running
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does qDup handle exit codes from piped commands? What would this print?
- sh: false | true
- sh: echo $?
Would pipefail work in qDup context?
- sh: set -o pipefail
settings: | ||
check-exit-code: true | ||
``` | ||
Exit code checking will automatically check the exit code of all `sh` commands that end with the default qDup prompt. We don't check the exit code of commands that end with a prompt from `add-prompt` because those commands are typically in a sub-shell that may not support exit codes. qDup will then abort if the exit code is non-zero. This is a very strict way to enforce exit codes and most scripts probably are not written to consider exit codes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also do
- sh:
command: maybe_fail
check-exit-code: true
or do you have to do this?
- sh: maybe_fail || echo "__command_failed__"
then:
- regex: "__command_failed__"
then:
- abort: command failed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both should work to end the run if maybe_fail
had a non-zero exit code
#> echo $? | ||
127 | ||
``` | ||
There are, however, times when a commands exit code provides important information. In those cases, we have two ways to work with exit codes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say "two ways to work with exit codes" because these are not really 'generic' ways. Rather sum it up as "abort on non-zero" and "process exit code as text" or something similar.
Bump, is this going to be improved any further? |
@willr3 is there any more to add to this doc? |
No description provided.