How to dynamically set a local Maven repository per a set of Jobs

1,146 views
Skip to first unread message

Samith Dassanayake

unread,
Apr 26, 2015, 6:12:56 AM4/26/15
to jenkins...@googlegroups.com
Hi all,
I want to set a local maven repository per set of jobs dynamically.(kind of a job partitioning method) For an example
job1, job2, job3  --> use /home/jenkins/dir1
job4, job5,  --> use /home/jenkins/dir2
job7  --> use /home/jenkins/dir3
etc..

Is there a way to define local maven repository location in the config.xml such that I can define which local maven repository to use, during the job creation per particular job?

Thanks,
Samith

Mark Waite

unread,
Apr 26, 2015, 6:51:30 AM4/26/15
to jenkins...@googlegroups.com

The maven build step includes an advanced button which allows you to configure the repository for that job.

Mark Waite


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/38b4d42b-298b-41cd-bfc2-f28a2b8c32c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samith Dassanayake

unread,
Apr 26, 2015, 9:12:21 AM4/26/15
to jenkins...@googlegroups.com
Hi Mark,
Yes. By setting "Use private Maven repository" option we can configure whether to use a private maven repository, But the possible values are default, local-to-workspace and local-to-executor. Therefore I cannot specify the local maven repository to use. 
What I want to do is each job will have their own workspace and set of jobs will share a single local maven repo

Example
JOB        WORKSPACE                   LOCAL MAVEN REPO
job1        JENKINS_HOME/job1       /home/jenkins/local_repo_1
job2        JENKINS_HOME/job2       /home/jenkins/local_repo_1
job3        JENKINS_HOME/job3       /home/jenkins/local_repo_1

job4         JENKINS_HOME/job4       /home/jenkins/local_repo_2
job5         JENKINS_HOME/job5       /home/jenkins/local_repo_2

Here job1,job2 and job3 will have their own workspace but share the local maven repository in " /home/jenkins/local_repo_1". But for job4 and job5 maven repository will be " /home/jenkins/local_repo_2". How can I configure jenkins to achieve that?

Thanks,
Samith

Mark Waite

unread,
Apr 26, 2015, 1:06:49 PM4/26/15
to jenkins...@googlegroups.com
Can the repository in use by a job be set from the settings.xml file?  If so, then you might use a "managed file" which contains the definition of the repository you want for a specific job.

The managed file is then assigned to the job through that same Advanced settings dialog.

Mark Waite

Samith Dassanayake

unread,
Apr 26, 2015, 1:41:14 PM4/26/15
to jenkins...@googlegroups.com
Hi Mark,
I didn't get your point.. Could you please elaborate more. It would be great-full, if you could provide an example. 

Thanks,
Samith

Mark Waite

unread,
Apr 26, 2015, 6:55:40 PM4/26/15
to jenkins...@googlegroups.com
I'm afraid I can't provide an example.  I was only guessing that it is possible, but don't have experience to prove it is possible.

When I read https://maven.apache.org/guides/mini/guide-configuring-maven.html , it seems to indicate that the settings.xml file can specify the location of the local repository directory.  It seems that if you can use the settings file to specify a job specific repository directory, you would probably also be able to use the settings file to have a subset of your jobs use a specific repository directory.

Mark Waite

Matt Stave

unread,
Apr 29, 2015, 10:13:09 AM4/29/15
to jenkins...@googlegroups.com
We have multiple Jenkins jobs using maven with the same userID with /home on a file system shared between slave nodes, so the default ~/.m2/repository led to ... nice speedups, but had the downside of doing The Wrong Thing, and causing errors.  So for jobs that call mvn in the middle of a bash step (as opposed to using the local option others pointed out with a Maven step) you can do mvn ... -Dmvn.repo.local=/path/you/want

You can probably put that in your settings.xml file.
Reply all
Reply to author
Forward
0 new messages