2

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?

Gabe Cohen
  • 85
  • 7

1 Answers1

2

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.

Paul Becotte
  • 9,767
  • 3
  • 34
  • 42
  • My image is a bit heavy; do you have to build it each time? – Gabe Cohen Sep 01 '15 at 17:53
  • 1
    docker has a build cache so it will only rebuild it if something has changed. (I don't add my source code to the image that we build for the tests... the image WITH the source code inherits from the base image I use here). If you would prefer to build it elsewhere that is perfectly fine, but this is the simplest way of ensuring you use the latest image that goes with this version of the sourcecode. – Paul Becotte Sep 01 '15 at 18:29