Skip to content

Instantly share code, notes, and snippets.

@jvmvik
Created November 21, 2023 13:13
Show Gist options
  • Save jvmvik/1e96e4e8ef7e4dd0e05df62a615deca5 to your computer and use it in GitHub Desktop.
Save jvmvik/1e96e4e8ef7e4dd0e05df62a615deca5 to your computer and use it in GitHub Desktop.
Shell broken on exit code 1

If the parent script runs with fail on error switch: tcsh -e but a sub script issue a exit code non zero. Then the parent will fail like a Jenkins pipeline, Bamboo job or else.

This switch allows easy pipeline debug by stopping the script when exit code > 0

/bin/tcsh -fe
source path/to/bin/sourceme
# display each command executed
set echo
# run commands until first exit code > 0

The issue was related to a grep -> exit code

hostname | grep "login"
if ($? == 0) {

The first line generates a exit 1 if the parent machine is not a login. In other word, it fails any pipeline but runs fine on a login machine.

Solution:

if (`hostname -f`== *login*) {

This simple fix should save countless hours to the team.

Note: first I tried $HOSTNAME which is not a reliable environment variable. Only the process hostname is predictable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment