如何使用Artifactory插件和凭据插件将Maven工件从Jenkins部署到Artifactory时解决401失败?

时间:2017-01-27 18:47:51

标签: maven jenkins artifactory

我使用Jenkins构建Maven项目。

我有Jenkins Credentials插件和Jenkins Artifactory插件。

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

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

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

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

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

然而,在我的Jenkins工作中,我想使用Artifactory插件和Credentials int 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部署。

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

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

2 个答案:

答案 0 :(得分:0)

假设您已正确配置凭据。如果您已经部署了版本,则可以对文件说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?并同意这样一个事实:一旦项目被共享,不应该为消费者随时改变,不允许部署阶段对于同一版本不止一次。

答案 1 :(得分:0)

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

相反,使用mvn install作为主构建任务,并设置新的构建后任务以将工件部署到存储库。

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

相关问题