Build not failing even test exit with code 1


#1

I have this test override:

test:
  override:
    - |
      if ( [ $CIRCLE_BRANCH = 'staging' ] || [ $CIRCLE_BRANCH = 'master' ] ); then
        docker run -d -p 0.0.0.0:8080:8080 my-app
      else
        ./gradlew test itest
        mkdir -p $CIRCLE_TEST_REPORTS/junit/
        find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
  fi

and even when:

 ./gradlew test itest
 FAILURE: Build failed with an exception.

The build passes as successful, now I implemented this ugly workaround:

test:
  override:
    - |
      if ( [ $CIRCLE_BRANCH = 'staging' ] || [ $CIRCLE_BRANCH = 'master' ] ); then
        docker run -d -p 0.0.0.0:8080:8080 my-app
      else
        ./gradlew test itest
        export EXIT=$?
        mkdir -p $CIRCLE_TEST_REPORTS/junit/
        find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
        if [ $EXIT -ne 0 ]; then
          exit 1
        fi
      fi

And now it fails, but I wonder if I am missing something if this is actually a bug, maybe related to:

https://circleci.com/docs/rspec-exit-codes/

Here is a very simple example:

https://circleci.com/gh/grebois/circle-5818/4


NPM exit code 1
#2

From support:

zzak (CircleCI)
Aug 28, 23:42 PDT

    Based on the output of your build, it seems you are using Bash.
    
    In this case, this is expected behavior because you're running through a pipeline. See the official documentation on pipelines, particularly:
    
    The exit status of a pipeline is the exit status of the last command in the pipeline, unless the pipefail option is enabled (see The Set Builtin). If pipefail is enabled, the pipeline’s return status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands exit successfully. If the reserved word ‘!’ precedes the pipeline, the exit status is the logical negation of the exit status as described above. The shell waits for all commands in the pipeline to terminate before returning a value.
    
    I recommend to use set -eo pipefail which handles exit status for you, so you don't have to deal with returning it yourself.
    
    Essentially -e will immediately exit if any command exists with a non-zero status, and -o pipefail does as described above (uses the exit status of the rightmost command to exit).
    
    Hope that helps!

#3

Does this mean your issue was solved? Mind sharing the fix you did here for others?


#4

set -o pipefail does not work for me. If I put this in a npm script tag, I get an error on the console:

sh: 1: set: Illegal option -o pipefail

I’m using the Ubuntu 14.04 (Trusty) image…


#5