【问题标题】:Jenkins Maven job doesn't use localRepository from settings.xmlJenkins Maven 作业不使用来自 settings.xml 的 localRepository
【发布时间】:2017-03-30 19:50:50
【问题描述】:

我有三个 Jenkins Maven 工作:一个构建和安装依赖项 (JAR),两个使用这些依赖项捆绑可部署的 WAR 文件。

我已将所有三个作业都配置为使用特定的 settings.xml 文件,并且虽然不完全理解 Settings file 和 Global Settings file 之间的区别(即使在阅读了?,也不清楚),在 构建我将两个字段都设置为我希望使用的文件路径,以防万一:

/opt/maven/conf/settings.xml 指定:

<localRepository>/var/lib/maven/repo</localRepository>

但是,依赖项会下载到不同的位置:/var/lib/jenkins/maven-repositories/1 因为/var/lib/jenkins 是JENKINS_HOME。

控制台输出记录以下内容:

执行 Maven:-B -f /var/lib/code/src/pom.xml -Dmaven.repo.local=/var/lib/jenkins/maven-repositories/2 -s /opt/maven/conf/ settings.xml -gs /opt/maven/conf/settings.xml 全新安装 -P depBuild

这令人困惑,因为maven.repo.local 与 -s 和 -gs 下列出的文件所说的不同。

为什么它没有在我告诉它使用的 settings.xml 中指定的本地 repo 中下载和安装依赖项?

这是整个 settings.xml:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <localRepository>/var/lib/maven/repo</localRepository>

  <servers>
    <server>
      <id>build.tomcat.all</id>
      <username>buildman</username>
      <password>mypass</password>
    </server>
  </servers>


  <pluginGroups></pluginGroups>

  <proxies></proxies>

  <mirrors></mirrors>

  <profiles></profiles>

</settings>

【问题讨论】:

  • 你能发布完整的 settings.xml 吗?您的源文件中是否还有其他 settings.xml?
  • 请看我的更新
  • 看起来 Jenkins 在执行 Maven 时使用命令行选项覆盖了本地存储库。该参数可能取自 Jenkins 主目录或安装目录中的.m2/settings.xml。你能查一下那个位置吗?
  • 可以在Jenkins的全局工具配置中更改默认的settings.xm。
  • 运行作业时,请查看控制台输出。它应该打印正在运行的确切内容;包含所有标志和选项的确切行。可能你会看到那里有些东西被覆盖了,这会有所帮助

标签: maven jenkins


【解决方案1】:

尝试使用Config File Provider Plugin 对其进行配置。安装此插件后,您可以在 Manage Jenkins > Managed files > Add a new Config > Maven 设置中创建配置文件。 xml.

它还从模板开始,因此您可以修改您需要的内容。我只是在注释说明之后添加了&lt;localRepository&gt; 标签。

然后在您的 Maven 作业中,选择“提供的 settings.xml”并选择您刚刚创建的配置文件。

确保您在MAVEN_OPTS 中没有任何覆盖选项,并且未选中“使用私有 Maven 存储库”。

PS:看起来您不需要使用“Global settings.xml”执行此操作 - 您可以将其保留为“使用默认值”。我有限的理解是全局设置影响maven系统的所有用户,而非全局设置只影响运行maven的用户。我认为这对大多数项目来说并不重要,但也许如果你有一个特殊的项目,其中一些 shell 执行发生在不同的用户下,这可能很重要。 (我只是猜测。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多