2

We have created a Docker build container to be run by Jenkins for Java based projects. We are using Maven for building our software. The problem we are facing is that, the builds are taking way to long to finish and the main reason for that is that maven is re-downloading all the dependencies for every single build, maven is run from inside the build container and not from the pipeline step.

We thought about using a shared folder but we have dynamic build agents so no shared folder. Is there anyone who is using the same approach and is there a better approach to this?

alecxe
  • 849
  • 1
  • 16
  • 36
Bambara
  • 123
  • 1
  • 3

1 Answers1

3

You might use docker builder pattern. Briefly you need to create Dockerfile.build which adds pom.xml and run mvn dependency:resolve:

FROM maven:latest
ADD ./pom.xml /src/pom.xml
WORKDIR /src
RUN mvn dependency:resolve

Rebuild that image every time prior build. Docker will use cached image if ./pom.xml has not changed.

Docker 17.05 introduced 'multi-stage builds' feature which implements this pattern. More information is available here: https://docs.docker.com/engine/userguide/eng-image/multistage-build/