How to add Maven local path in Jenkins that is running in a docker container

Hi All,

I have maven installed in my windows machine (here is the path: C:\Program Files\apache-maven-3.8.4) and Jenkins running in a docker container.

When I try to add maven path in Jenkins >> Global Tools Configuration, It is giving me the following error

C:\Program Files\apache-maven-3.8.4\ is not a directory on the Jenkins controller (but perhaps it exists on some agents)

Is it possible to refer locally installed maven or JDK path in Jenkins which is running in a docker container? If yes, can you provide a sample working path

Thanks, Bala

If you want something outside of docker to be accessible inside of jenkins, then you want to mount the volume.

Or you can tell jenkins tools system to install it on demand (extract the zip).

@halkeye Thanks for the response. If I understand correctly you are suggesting me to mount the following folder(s) to docker Jenkins volumes? please correct me if my understanding is wrong.

C:\Program Files\apache-maven-3.8.4\ and also .m2 repo folder

I have seen creating volumes to copy docker container folders to local machine for persistence purpose using -v or volumes option. However, I have not seen an option for other way round (like mounting local folder to docker jenkins). Can you please provide any reference or sample command?

This is not a Jenkins question but you can easily attach any local path as a “volume” using -v

While it might be technically possible to make that path visible in your container I think that you are conceptionally on the wrong way. It does not make sense to use a Java or Maven installation from outside the container. Just let your builds run on an agent that contains the correct tools. Or use Jenkins’ tool installation to install the correct tools automatically.

1 Like