React to failure of shell script in Job

Hello,

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

```
job("My Job") {
  host {
    shellScript(displayName = "My Script") {
      content = """
        ./my-script.sh
      """"
    }
  }
}
````

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?

0
1 comment

Hello!

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 https://www.jetbrains.com/help/space/sharing-execution-context.html#accessing-file-share-directly 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 ./my-script.sh. It's not using set -e so the failure of ./my-script.sh 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 = "my-script.sh", which would not suffer from this problem.

0

Please sign in to leave a comment.