【问题标题】:Binding nexus credentials to maven deploy job in jenkins build将 nexus 凭据绑定到 jenkins 构建中的 maven 部署作业
【发布时间】:2019-12-02 13:23:42
【问题描述】:

我有一个 maven pom 项目,在 pom.xml 中定义了 distributionManagement 部分

<project>
...
    <distributionManagement>
        <repository>
            <id>my-repo</id>
            <url>http://nexus.my.local/repository/my-private</url>
        </repository>
    </distributionManagement>

</project>

settings.xml 文件中我设置了servers 部分

  <servers>
    <server>
      <id>my-repo</id>
      <username>${env.CI_DEPLOY_USERNAME}</username>
      <password>${env.CI_DEPLOY_PASSWORD}</password>
    </server>
  </servers>

在 jenkins 中,我将凭据绑定到这些变量 但是做mvn clean deploy 会给我以下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project XY:
Failed to deploy artifacts:
Could not transfer artifact XY:pom:1.0.0 from/to my-repo (http://nexus.my.local/repository/my-private):
Failed to transfer file: http://nexus.my.local/repository/my-private/XY-1.0.0.pom.
Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]

当我在构建之前在 shell 中回显变量 ${CI_DEPLOY_USERNAME} 时,它给了我 **** 输出 -> 我认为没关系。 我还应该在哪里提供变量?我项目的settings.xml 是否在 maven deploy 命令中使用?

【问题讨论】:

    标签: maven jenkins credentials maven-deploy-plugin


    【解决方案1】:

    在 Maven 中使用环境变量作为属性要求它们以 env. 为前缀,所以应该是:

      <servers>
        <server>
          <id>my-repo</id>
          <username>${env.CI_DEPLOY_USERNAME}</username>
          <password>${env.CI_DEPLOY_PASSWORD}</password>
        </server>
      </servers>
    

    参考

    http://maven.apache.org/pom.html#Properties

    【讨论】:

    • 您是否为 Jenkins 用户修改了settings.xml?您可以通过 SSH 连接到 Jenkins 代理并手动运行 mvn 作为测试吗?
    • 不,我在我的项目settings.xml中修改了它,将尝试ssh
    • 好吧,我的settings.xml 有内联评论,这导致 maven 命令无法接收 :( 谢谢你的帮助
    • 很高兴您解决了您的问题。
    猜你喜欢
    • 2014-12-28
    • 2012-05-19
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 2013-03-06
    • 2016-10-19
    • 2015-12-04
    • 2018-01-21
    相关资源
    最近更新 更多