Jenkins Maven的工作并没有使用settings.xml中的localRepository

时间:2017-03-30 19:50:50

标签: maven jenkins

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

我已将所有三个作业配置为使用特定的settings.xml文件,但未完全理解Settings fileGlobal Settings file之间的差异(即使在阅读了?之后,它也是&# 39;不清楚),在构建下,我将两个字段都设置为我想要使用的文件路径,以防万一:

enter image description here

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

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

但是,依赖项会被下载到其他位置:/var/lib/jenkins/maven-repositories/1 /var/lib/jenkinsJENKINS_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 clean install -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>

1 个答案:

答案 0 :(得分:0)

尝试使用Config File Provider Plugin进行配置。安装此插件后,您可以在管理Jenkins &gt;中创建配置文件。 托管文件&gt; 添加新配置&gt; Maven settings.xml

它还会让您开始使用模板,这样您就可以修改所需内容。我刚刚在评论说明之后添加了<localRepository>标记。

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

确保MAVEN_OPTS中没有任何重写选项,并且未选中“使用私有Maven存储库”

enter image description here

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