【问题标题】:How can I resolve a 401 failure when deploying a Maven artifact from Jenkins to Artifactory using the Artifactory Plugin and the Credentials Plugin?使用 Artifactory 插件和凭据插件将 Maven 工件从 Jenkins 部署到 Artifactory 时,如何解决 401 故障?
【发布时间】:2017-06-13 13:10:52
【问题描述】:

我使用 Jenkins 构建一个 Maven 项目。

我有 Jenkins 凭据插件和 Jenkins Artifactory 插件。

我已在凭据配置中添加了我的 Artifactory 凭据。

我已将 Artifactory 插件配置为使用凭据并设置服务器 URL。测试连接工作并报告它已找到服务器。

我的项目的 POM 为 distributionManagement 部分中的 repositorysnapshotsRepository 指定了正确的 Artifactory 路径。

我的 Jenkins 项目构建配置为执行 mvn deploy

在我的本地构建中,我可以从我的开发机器部署到 Artifactory 服务器(我已在 settings.xml 中配置了凭据。

但是,在我的 Jenkins 工作中,我想使用 Artifactory 插件和 Credentials 插件中的 Credentials。当我构建时,我得到以下内容

[DEBUG] Using connector WagonRepositoryConnector with priority 0 for http://xxxxx/artifactory/libs-release-local
Uploading: http://xxxxx/artifactory/libs-release-local/xxx/3.01/xxx-3.01.war
Uploading: http://xxxxx/artifactory/libs-release-local/xxx/3.01/xxx-3.01.pom
Notifying upstream projects of job completion
Join notifier requires a CauseAction
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

以及下面的堆栈跟踪

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project querynator: 
Failed to deploy artifacts: Could not transfer artifact xxx:war:3.01 from/to dwCentral (http://xxxxx/artifactory/libs-release-local): 
Failed to transfer file: http://xxxxx/artifactory/libs-release-local/xxx/3.01/xxx-3.01.war. 
Return code is: 401, ReasonPhrase: .

这表明问题出在凭据上,特别是因为我可以从我的开发箱部署(使用 settings.xml 中的凭据),但不能从 Jenkins 部署。

我已尝试部署新版本。我尝试过部署快照。这不是版本问题。

我该如何解决这个问题?如何进一步解决此问题?

【问题讨论】:

    标签: maven jenkins artifactory


    【解决方案1】:

    假设您已经正确配置了凭据。如果您已经部署了版本,请对工件说一次x.y.z。执行命令

    mvn deploy
    

    同样的版本也会导致

    返回码是:401,ReasonPhrase:未授权。

    您可以尝试将版本更新为从未部署过的x.y.a,该作业应该可以正常运行。


    更多来自Maven Lifecycle Basics 的文档

    deploy - 在构建环境中完成,将最终包复制到 用于与其他开发人员和项目共享的远程存储库。

    并假设您了解What exactly is a Maven Snapshot and why do we need it? 并同意这样一个事实,即一旦跨事物共享项目不应该为消费者即时更改,部署阶段对于同一版本不止一次。

    【讨论】:

    • 这不是版本问题。我尝试过部署新版本,也尝试过部署快照
    【解决方案2】:

    在 Jenkins 中使用 Artifactory 插件时,不应在主构建任务中使用 mvn deploy。它使用 Maven 部署插件,因此将尝试使用存储在 settings.xml 文件中的凭据。

    改为使用mvn install 作为主要构建任务,并设置一个新的构建后任务来将工件部署到存储库。

    这允许您定义要使用的服务器、存储库位置和凭据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 2015-04-19
      • 2021-04-25
      • 2011-07-24
      相关资源
      最近更新 更多