Search code examples
jenkinsdockerjenkins-docker

Run tests using Jenkins in a Docker Container


I've seen a few resources that connect Jenkins and Docker, but none exactly like what I'm trying to do, which is to have Jenkins:

  1. Pull latest code from GitHub
  2. Start Docker container and share pulled code with it
  3. Run tests in Docker container
  4. Generate report of test results

I'm lost on how to get code from GitHub into my Docker container when using Jenkins. I have the container that I use for local testing, but am trying to automate the process with Jenkins. Can anyone point me in the right direction?


Solution

  • We do exactly that. We use the regular Jenkins Git plugin to fetch a copy of the source code. Then we run our docker container to run the tests...

    # docker-compose.yml
    web:
      build: .
      volumes:
        - .:/src
      command: /src/run-tests.sh
    
    docker-compose run web
    

    Mount a volume so that Jenkins can access any output from the tests, such as junit xml results.