Within my team's CI/CD pipeline, we have the following Make recipe:
test-some-service:
echo "Running some tests...." && \
docker-compose up service-target-test && \
status=$$?; \
# ...
exit $$status
Despite collecting the docker-compose exit status, when it fails, the CI pipeline still pass with a false positive.
service-target-test-1 | FAILED (errors=1)
service-target-test-1 | make: *** [Makefile:2: test] Error 1 exited with code 2
...
...
success!
This is causing developers to push breaking code without knowing the changeset is not passing our quality checks. We have tried to refactor this recipe multiple times but still getting the same issue. What are we doing wrong here?
Please use docker compose run
instead of docker compose up
:
test-some-service:
set -e && \
echo "Running some tests...." && \
# ...
docker-compose run --rm service-target-test
The run command acts like docker run -ti in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container.
The docker compose run
command is more suitable for running "one-off" or "adhoc" tasks.
See: