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

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

问题描述

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

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.

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

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.

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

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. 阻止 Jenkins 错误地将 .jar 安装到本地存储库
  2. 防止本地存储库在以下情况下被使用构建依赖库的项目

推荐答案

安装 目标是发布到本地存储库...所以我对第一个问题没有答案.

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 将 Artifact 安装到本地 Maven 存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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