How to separate write access to Maven repositories in Jenkins?

In order to prevent that one build influences another it is possible to configure a Jenkins project to use a own private Maven repository. However, because we have actually a huge list of dependencies, this leads to a lot of wasted disk space and to slow builds. We use a Maven repository proxy, but still the time to download artifacts over the local network is significant.

I could set up another repository proxy directly on the Jenkins machine. Is there an easier solution?

I still want that any "maven install" goes to a project-specific repo, while reading of artifacts that have not been deployed to that project-specific repo should come from a central place on the local file-system. Those artifacts should not be copied for performance and disk space reasons.

To explain the background I append the help text of the "Use private Maven repository" option:

"Normally, Jenkins uses the local Maven repository as determined by Maven — the exact process seems to be undocumented, but it's ~/.m2/repository and can be overridden by in ~/.m2/settings.xml (see the reference for more details.)

This normally means that all the jobs that are executed on the same node shares a single Maven repository. The upside of this is that you can save the disk space, but the downside of this is that sometimes those builds could interfere with each other. For example, you might end up having builds incorrectly succeed, just because your have all the dependencies in your local repository, despite that fact that none of the repositories in POM might have them.

There are also some reported problems regarding having concurrent Maven processes trying to use the same local repository.

When this option is checked, Jenkins will tell Maven to use $WORKSPACE/.repository as the local Maven repository. This means each job will get its own isolated Maven repository just for itself. It fixes the above problems, at the expense of additional disk space consumption.

When using this option, consider setting up a Maven artifact manager so that you don't have to hit remote Maven repositories too often.

If you'd prefer to activate this mode in all the Maven jobs executed on Jenkins, refer to the technique described here."


You could have:

  • one settings.xml that points to a common local repository, used for every mvn clean package command
  • and one settings.xml per projet that uses a specific local repository for every mvn install command
  • In order you would:

    mvn clean package -s settings-common.xml # using common-repo
    mvn install -s settings-jobX.xml # using jobX-repo
    

    The only issue is that the artifact installed by your job wouldn't be available to other jobs if they need it. You'd have to either deploy, or copy manually the artifact to the common-repo.

    Please note that I do not understand fully what you mean by "one build influences another". You should clarify that in order to have a better answer (because what you want to do might not be what's best to do).

    链接地址: http://www.djcxy.com/p/66394.html

    上一篇: Jenkins工作区未显示在不同节点上的并发构建

    下一篇: 如何在Jenkins中将写入权限分开到Maven仓库?