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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

My image is a bit heavy; do you have to build it each time?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.