防止Jenkins将工件安装到本地Maven存储库 [英] Prevent Jenkins from Installing Artifact to Local Maven Repository

查看:432
本文介绍了防止Jenkins将工件安装到本地Maven存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使仅以clean package为目标执行作业,Jenkins仍将最新构建的工件安装到本地Maven存储库中.

当某人不小心提交了共享库的更新版本而未增加该库的POM中的版本号时,这引起了一个问题. Jenkins构建了jar,将其安装到本地Maven存储库,然后(按配置)将工件部署到我们的共享Nexus存储库. Nexus非常正确地拒绝接受新的工件,因为它已经具有具有给定版本号的发行版.

一段时间之后,詹金斯(Jenkins)建立了一个依赖于该库的项目,并使用该库的副本来自其 local Maven存储库,而不是Nexus.因此,该项目是使用错误版本的代码构建的.

似乎有两种可能的解决方案:

  1. 阻止Jenkins将.jar错误地安装到本地 仓库
  2. 防止在以下情况下使用本地存储库 建立依赖图书馆的项目

解决方案

这是发布到本地存储库的 install 目标……因此,我对第一个问题没有答案.

第二个问题可以通过隔离每个构建来解决.配置它们以使用自己的本地存储库,以使其中一个错误不会影响其他错误:

mvn -s settings.xml compile package

在设置文件中为构建作业的本地存储库声明唯一路径

<settings>
  <localRepository>/data/job1/repository</localRepository>
  ..

定期清除本地存储库,强制进行干净的构建是一个好主意.

Jenkins is installing the most-recently built artifact to the local Maven repository, even when the job is executed with a goal of only clean package.

This caused an issue when someone accidentally committed an updated version of a shared library without incrementing the version number in the library's POM. Jenkins built the jar, installed it to the local Maven repository, and then (as configured) deployed the artifact to our shared Nexus repository. Nexus quite rightly refuses to accept the new artifact, as it already has a release with the given version number.

Some time later Jenkins builds a project that depends on that library, and uses the copy of the library from its local Maven repository rather than Nexus. Thus the project got built with the wrong version of the code.

It seems there are two possible solutions:

  1. Stop Jenkins from erroneously installing the .jar to the local repository
  2. Prevent the local repository from being used when building projects that depend on the library

解决方案

It's the install goal that publishes to the local repository... So I've no answer for the first problem.

The second problem can be solved by isolating each build. Configure them to use their own local repositories so that mistakes in one don't affect others:

mvn -s settings.xml compile package

In the settings file declare unique path for the build job's local repository

<settings>
  <localRepository>/data/job1/repository</localRepository>
  ..

And it's probabily a good idea to periodically purge the local repositories, forcing clean builds.

这篇关于防止Jenkins将工件安装到本地Maven存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆