1

I am setting up 2 jenkins instances on same server. I would like to create 2 local maven repositories for both jenkins seprately. Jenkins 1 is already set up and operational and I woudnt like to touch it.

Can we have 2 local maven repositories for single user as both jenkins are running as the same user ?

Is there any way I can point maven from jenkins to the new repository ?

Thanks

AI

aitankar
  • 21
  • 2
  • Consider if this answer helps you: https://stackoverflow.com/questions/6823462/specifying-mavens-local-repository-location-as-a-cli-parameter – user2515975 Sep 09 '20 at 09:55

3 Answers3

1

Thanks for your replies, I figured it out, every maven command I am running, I am adding extra parameter -Dmaven.repo.local=/path/to/alternate/local/repository/

and it overrides default local maven repository.

Cheers,

AI

aitankar
  • 21
  • 2
0

You can specify a local repository in the settings.xml under <settings><localRepository>.

Alternatively, you can also specify it on the command line as described here:

https://stackoverflow.com/a/7071791/927493

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

Maven configuration occurs at 3 levels:
◾ Project - most static configuration occurs in pom.xml
◾ Installation - this is configuration added once for a Maven installation
◾ User - this is configuration specific to a particular user

Maven reads the settings from the settings.xml file which can be located in ${M2_HOME}/conf/settings.xml, as well as ${user.home}/.m2/settings.xml

<settings>
  ...
  <localRepository>/path/to/local/repo/</localRepository>
  ...
</settings>

The default value for the local maven repository is ${user.home}/.m2/repository/

Even though you are are constrained in that you are using the same use for both Jenkins, remember the jobs run on nodes and those can be launched by different users (if via SSH), but it's that node's user's ${user.home}, not the user running Jenkins itself which is read (See Node note below).

What's the simplest way to get two different <localRepository> for a given user?


Jenkins has a Global Tool Configuration (${JENKINS_URL}/configureTools) for Maven: Global Maven Configuration

Further down the the same page you must configure the Maven installations Maven installation

You could choose the Global Tool Configuration | Maven Configuration to NOT use the default maven settings (the two mentioned above) and specify one from the filesystem:

One one instance, choose ${user.home}/.m2/settings.J1.xml,
and on the other, choose ${user.home}/.m2/settings.J2.xml

Alternatively, you could even choose two different "Maven installations", with a different MAVEN_HOME, then have a different ${M2_HOME}/conf/settings.xml in each (awkward, but sometimes useful).

JOB SPECIFIC REPO?

But, if disk space is not really an issue, you could go a step further and give every single job its own private local repository. This is especially handy when building shared libraries in parallel, parallel branches and other scenarios using -SNAPSHOT. Under the Advanced ... options in the maven step, select [ X ] use private Maven repository. That repository ends up residing in ${WORKSPACE}/.repository. Suggest adding the Workspace Cleanup plugin to help manage your space.

Job-level Maven Configuration

You can also, on a per-job basis, specify a specific file-system settings.xml.

NODE SPECIFIC REPO?

Also, each Node has its own Node Properties which again let you customize the "Tool Locations". You can override the "(Maven) Home" location here (but not settings location).

[Node tool configuration5

PIPELINE

All this is also supported and configurable if using a Pipeline, as described in the Pipeline Maven Integration Plugin.

Extra Plugins

Finally, if you don't like the idea of having all these settings.xml lying all over the filesystems, you can install the Config File Provider plugin which lets you store the custom settings.xml within Jenkins. After installation, the Global Tool Configuration (shown) and Job steps now has the added option to choose from the "provided settings.xml" options you create: Global Tool w/Managed File

Ian W
  • 4,559
  • 2
  • 18
  • 37