We have a Maven Java project that we want to run in Jenkins BlueOcean pipelines.
I followed this tutorial. The pipeline is working to execute our code. Yay!
However, every time the 'build' stage of our pipeline executes under a new Jenkins run, it re-downloads all the maven artifacts. This increases our build time considerably.
I start the 'jenkins-docker' container with:
docker container run --name jenkins-docker --rm --detach \
--privileged --network jenkins --network-alias docker \
--env DOCKER_TLS_CERTDIR=/certs \
--volume jenkins-docker-certs:/certs/client \
--volume jenkins-data:/var/jenkins_home \
--publish 2376:2376 docker:dind
And the 'jenkins-blueocean' container with:
docker container run --name jenkins-blueocean --rm --detach \
--network jenkins --env DOCKER_HOST=tcp://docker:2376 \
--env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 \
--volume jenkins-data:/var/jenkins_home \
--volume jenkins-docker-certs:/certs/client:ro \
--publish 8080:8080 --publish 50000:50000 jenkinsci/blueocean
Then our Jenkinsfile pipeline is:
pipeline {
agent {
docker {
image 'maven:3.6.3-jdk-8'
args '-v /root/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests clean package'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
}
}
Here, Jenkins launches a new 'maven:3.6.3-jdk-8' docker image to do the run. It's also mapping a volume to persist the .m2 directory, as I understand.
Since my 'jenkins-docker' instance isn't shutting down across builds, I'd like to have this .m2 directory persisted. Then each successive run can leverage the cache of downloaded artifacts and not spend 5 minutes re-downloading them.
Is anyone able to offer any insight to what I'm doing wrong?
Thanks in advance