0

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.

Xeperis
  • 1,449
  • 2
  • 25
  • 41
  • Please provide your job configuration yaml. – sytech Apr 15 '22 at 19:46
  • @sytech ```yaml e2e: stage: build tags: [high_performance] script: - docker-compose up --build e2e after_script: - docker-compose down ``` > docker-compose up --build e2e this builds and starts the entire application and finally runs a container that executes tests > Dockerfile looks like this ``` FROM node:14.18.1-alpine3.14 COPY CMD ["yarn", "test"] ``` Everything runs just fine, though it does not matter if container exits with status != 0 during CMD – Xeperis Apr 19 '22 at 12:00

1 Answers1

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

sytech
  • 29,298
  • 3
  • 45
  • 86