2

I am running an sh script as part of my .travis.yml. It is giving me the error below although the shell script does not fail.

The command exited with 1.

I tried running the with bash -x to debug and there are no errors. The problem is that travis thinks that the build failed although it passed.

mosaad
  • 2,276
  • 5
  • 27
  • 49

1 Answers1

2

This change fixes it.

As explained in the man bash page:

Shell builtin commands return a status of 0 (true) if successful, and non-zero (false) if an error occurs while they execute. All builtins return an exit status of 2 to indicate incorrect usage.

Bash itself returns the exit status of the last command executed, unless a syntax error occurs, in which case it exits with a non-zero value. See also the exit builtin command below.

The last command executed is:

[ "$BUILD_CHROMIUM" == 1 ] &&_build_chromium_crx "${zip_file}" "${BUILD_METADATA[${CHROMIUM_TARGET}]}"

And it is evaluated as false with exit status 1:

'[' 0 == 1 ']'

So adding || true at the end of this line fixes it. The exit status will always be 0.

Alternatively, use the fix that better suits the expected behavior of your code like exit 0, etc.

As explained here and here:

exit [n] Cause the shell to exit with a status of n. If n is omitted, the exit status is that of the last command executed. A trap on EXIT is executed before the shell terminates.

So your clean function trap _clean_chrome EXIT is not the last to be executed.

Further information about exit status here.

albodelu
  • 7,931
  • 7
  • 41
  • 84