'How to fail gitlab pipeline from docker container?

I run tests inside docker container on a shell runner (NodeJS/jest);

How can I fail gitlab pipeline if tests fail from inside the container?

  • I've tried process.exit(1) in case there are failing tests but it didn't help.
  • I considered running tests as part of Dockerfile RUN but I need the environment variables to configure URLs to other containers.

Since all tests are http calls to other containers I also expect that after_script will work for tearing down the environment regardless of the outcome.



Solution 1:[1]

When using docker compose, you'll need to use the --exit-code-from to specify the service that should be used for the exit code of the docker-compose command.

See also: https://stackoverflow.com/a/43367250/5747944

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sytech