(False Positive) Running docker-compose with gitlab-ci: Build job fails but pipeline succeeds

I am trying to get gitlab-ci to run my docker-compose file to build the integration environment, run the tests, and then either success or fail.

The dockerfile for my integration tests:

FROM maven:3.5.4-jdk-8
VOLUME /tmp
COPY / /tmp
WORKDIR /tmp
CMD mvn clean verify -P integration-test

Docker compose file:

services:
  integration:
    build:
      context: ./
      dockerfile: docker/integration/Dockerfile
    container_name: app_integration
    restart: always

gitlab-ci.yml:

integration_tests:
  stage: test
  only:
    - branches
  script:
    - docker-compose -f docker-compose.integration-test.yml up --exit-code-from=integration --force-recreate

Console output:

app_integration | [INFO] 
app_integration | [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
app_integration | [INFO] 
app_integration | [INFO] 
app_integration | [INFO] --- maven-failsafe-plugin:2.22.1:verify (integration-tests) @ app ---
app_integration | [INFO] ------------------------------------------------------------------------
app_integration | [INFO] BUILD FAILURE
app_integration | [INFO] ------------------------------------------------------------------------
app_integration | [INFO] Total time: 01:09 min
app_integration | [INFO] Finished at: 2018-10-22T17:53:33Z
app_integration | [INFO] ------------------------------------------------------------------------
app_integration | [ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.22.1:verify (integration-tests) on project app: There are test failures.
app_integration | [ERROR] 
app_integration | [ERROR] Please refer to /tmp/target/failsafe-reports for the individual test results.
app_integration | [ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
app_integration | [ERROR] -> [Help 1]
app_integration | [ERROR] 
app_integration | [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
app_integration | [ERROR] Re-run Maven using the -X switch to enable full debug logging.
app_integration | [ERROR] 
app_integration | [ERROR] For more information about the errors and possible solutions, please read the following articles:
app_integration | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
app_integration exited with code 1
Stopping app_integration ... 

Stopping app_integration ... done
Aborting on container exit...
Job succeeded

Right now, I’m running a single test which runs an assert false test, and should fail. However, I cannot get the pipeline to fail as it is “supposed to.”

What is the exit code, when you locally run:

docker-compose -f docker-compose.integration-test.yml up --exit-code-from=integration --force-recreate
echo $?

$ docker-compose -f docker-compose.integration-test.yml up --exit-code-from=integration --force-recreate; echo $?

app_integration | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
app_integration exited with code 1
Aborting on container exit...
Stopping app_integration   ... done
0

Hmm interesting.

I explored a little further, and when I ran compose without the --force recreate:
docker-compose -f docker-compose.integration-test.yml up --exit-code-from=integration; echo $?

app_integration | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
app_integration exited with code 1
Aborting on container exit...
Stopping app_integration   ... done
1

However, the gitlab-ci job still succeeds.

Update: I figured this out. It was the restart: always that was causing the problem. Removing this line makes the build function as desired.