Unexpected exit codes after explicit exit 1 / 0

Hi all,
I’m setting up sa quick check to avoid being able to push unsafe dependencies. We are using yarn and updating it right before, I tried to run the same commands ssh-ing into the failed job and they seems to work as expected.

Unsafe run
Last run with safe dependencies

#!/bin/bash -eo pipefail
SUMMARY="$(yarn audit | grep Severity)"
VULNERABILITIES=".*(High|Critical).*"

if [[ $SUMMARY =~ $VULNERABILITIES ]]; then
  echo "Unsafe dependencies found: $SUMMARY"
  exit 1
fi
echo "Your dependencies are secure enough: $SUMMARY"
exit 0
# outcome if is safe Exited with code 2
# outcome if unsafe Exited with code 10

Am I doing something wrong in using the command?

With SSH I tried the oneliner version:
SUMMARY="$(yarn audit | grep Severity)" ; VULNERABILITIES=".*(High|Critical).*" ; if [[ $SUMMARY =~ $VULNERABILITIES ]]; then echo "problems $SUMMARY" >&2; exit 1 ; fi ; echo "OK $SUMMARY" ; exit 0

And it worked as I would expect in SSH, exit with exit code 2 on workflow
Oneliner that should exit 0

Thanks,
Karoly

1 Like

The solution was easier than expected:
As first line I should have added

set +e

As the first line of command set implicitely
#/bin/bash -eo

It’s working properly now.

#!/bin/bash -eo pipefail

set +e

SUMMARY="$(yarn audit | grep Severity)"
VULNERABILITIES=".*(High|Critical).*"
.....

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.