React to failure of shell script in Job


I have an automation job that looks something like this (simplified version):

job("My Job") {
  host {
    shellScript(displayName = "My Script") {
      content = """

I would like to send a notification when the shell script exits with a non-zero exit code.
Sending the notification is not a problem, but I couldn't find a way to react to the non-zero exit code. Is there a way to do this without having to do it from within the shell script?

1 comment


Currently, Space doesn't provide the out-of-the-box support for this, but one of the possible workarounds might be to touch some file in FileShare in case when my-script exits with a non-zero code, and send notification in the next step when the file exists.

Please note that we do support notifications for failed jobs out of the box (with the Space notifications system). A non-zero exit code for a script means a failed step and thus a failed job if the failure condition for this has not been explicitly disabled.
That said, this particular shell script action is defined using content, so the shell script is effectively a file with only one line ./ It's not using set -e so the failure of ./ might not be considered a failure of the shell script action and thus the exit code is likely 0.
Note that we do support calling existing shell script files directly by using location = "", which would not suffer from this problem.


Please sign in to leave a comment.