Running Tests with Docker and Jenkins - Test Result

I have an application written in Rails. To test this, I created a docker image. Everything is working fine.

The problem, however, occurs when I configure Jenkins to run these tests. Here is what I do during the construction phase:

docker-compose up rspec 

Where rspec is the service defined in the docker-compose.yml file and contains the following command:

 command: "rspec spec/" 

When rspec returns an error, the assembly is still in progress. Here is an example output:

  ... 21:42:24 [36mrspec_1 |[0m should save second profile 21:42:24 [36mrspec_1 |[0m 21:42:24 [36mrspec_1 |[0m Failures: 21:42:24 [36mrspec_1 |[0m 21:42:24 [36mrspec_1 |[0m 1) New profile Should persist new_profile_pricture 21:42:24 [36mrspec_1 |[0m Failure/Error: jump_to_four_phase_with(new_profile_picture) 21:42:24 [36mrspec_1 |[0m RuntimeError: 21:42:24 [36mrspec_1 |[0m Timeout for '#new_profile' (1) appearance reached! ... 21:42:25 [36mcomposes_rspec_1 exited with code 1 21:42:25 [0m[Profiler] $ /bin/sh -xe /tmp/hudson4606189750126491465.sh 21:42:25 Finished: SUCCESS 

36mcomposes_rspec_1 returned 1, and the build still succeeded.

If I check the container against its id using docker ps -a , I get "Exited (1) 2 minutes ago"

Do you guys know what's going on?

Is there an easy way to fail assembly when the container fails?

0
ruby-on-rails docker continuous-integration jenkins rspec
source share
1 answer

Jenkins uses process exit status to measure success or failure.

docker-compose up designed to organize multiple containers. When dealing with multiple services / containers, there is a slightly gray area regarding what constitutes success and failure. All that docker-compose reports on exit is that the docker-compose completed successfully, and not all of the containers that it launched were in order.

docker-compose run <service> <command> will run one command for the service and return the completion status of the commands.

If you rely on several services / containers for tests, then docker-compose up will only display the necessary services. Then run docker-compose run rubyservice rspec for testing.

Make up the separation

If you want to keep the tests separate from the application containers, create a second docker-compose-test.yml file containing a service definition for tests only.

 version: "2.1" tests: build: context: . dockerfile: Dockerfile.tests cmd: rspec 

Once your main application containers have been raised, run

 docker-compose run -f docker-compose-test.yml tests 
+2
source share

All Articles