简体   繁体   English

如何使用Artifactory插件和Credentials插件将Jenven的Maven工件部署到Artifactory时解决401失败?

[英]How can I resolve a 401 failure when deploying a Maven artifact from Jenkins to Artifactory using the Artifactory Plugin and the Credentials Plugin?

I use Jenkins to build a Maven project. 我使用Jenkins构建一个Maven项目。

I have the Jenkins Credentials Plugin and the Jenkins Artifactory Plugin. 我有Jenkins Credentials插件和Jenkins Artifactory插件。

I have added my Artifactory credentials in the Credentials config. 我在Credentials配置中添加了Artifactory凭据。

I have configured the Artifactory plugin to use the Credentials and have set up the server URL. 我已将Artifactory插件配置为使用凭据并设置了服务器URL。 Test Connection works and reports back that it has found the server. 测试连接工作并报告它已找到服务器。

My project's POM specifies the correct Artifactory paths for the repository and the snapshotsRepository in the distributionManagement section. 我的项目的POM指定repository的正确Artifactory路径和distributionManagement部分中的snapshotsRepository

My Jenkins project build is configured to do a mvn deploy . 我的Jenkins项目构建配置为执行mvn deploy

In my local build, from my development machine, I can deploy to the Artifactory server (I have configured the credentials in my settings.xml . 在我的本地构建中,从我的开发机器,我可以部署到Artifactory服务器(我已在settings.xml配置了凭据。

However, in my Jenkins job, I want to use the Artifactory plugin and the Credentials int he Credentials plugin. 但是,在我的Jenkins工作中,我想使用Artifactory插件和Credentials int Credentials插件。 When I build, I get the following 当我建立时,我得到以下内容

[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] ------------------------------------------------------------------------

and the following stack trace 和以下堆栈跟踪

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: .

This indicates to me the issue is with credentials, particularly since I can deploy from my dev box (using credentials in settings.xml), but not from Jenkins. 这向我表明问题在于凭证,特别是因为我可以从我的开发箱(使用settings.xml中的凭据)部署,但不能从Jenkins部署。

I have tried deploying a new version. 我尝试过部署新版本。 I have tried deploying snapshots. 我尝试过部署快照。 This is not a version issue. 这不是版本问题。

How can II resolve this? 我怎么解决这个问题? How can I troubleshoot this further? 我该如何进一步排除故障?

When using the Artifactory plugin in Jenkins, you should not use mvn deploy in the main build task. 在Jenkins中使用Artifactory插件时,不应在主构建任务中使用mvn deploy That uses the Maven Deploy Plugin, and hence will try to use credentials stored in the settings.xml file. 它使用Maven Deploy插件,因此将尝试使用settings.xml文件中存储的凭据。

Instead, use mvn install as the main build task, and set up a new post-build task to Deploy Artifact to Repository. 相反,使用mvn install作为主构建任务,并设置一个新的构建后任务以将工件部署到存储库。

This allows you to define the server, repository locations, and credentials to use. 这允许您定义要使用的服务器,存储库位置和凭据。

Assuming you have already configured the credentials properly. 假设您已正确配置凭据。 If you have already deployed version lets say xyz to the artifactory once. 如果您已经部署了版本,请将xyz说成一次。 Executing the command 执行命令

mvn deploy

again for the same version would also result in the 同样的版本也会导致

Return code is: 401, ReasonPhrase: Unauthorized. 返回码为:401,ReasonPhrase:未经授权。

You can try updating the version to xya which has never been deployed, the job should just run fine. 您可以尝试将版本更新为从未部署过的xya ,该作业应该运行正常。


More from the documentation at Maven Lifecycle Basics 更多来自Maven Lifecycle Basics的文档

deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects. deploy - 在构建环境中完成,将最终包复制到远程存储库以与其他开发人员和项目共享。

and assuming that you understand What exactly is a Maven Snapshot and why do we need it? 并假设你了解什么是Maven快照,为什么我们需要它? and agree upon the fact that once a project is shared across things shouldn't be changing on the fly for consumers, the deploy phase is not permitted for the same version more than once. 并且同意这样一个事实:一旦项目被共享,不应该为消费者随时改变,不允许同一版本的部署阶段不止一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 rtMavenRun() 工件插件未使用 jenkins 中配置的凭据 - rtMavenRun() artifactory plugin not using credentials configured in jenkins 使用Artifactory Jenkins插件从嵌套项目中部署工件 - Deploying artifacts from nested projects using Artifactory Jenkins plugin artifactory-maven-plugin:如何在不使用settings.xml的情况下解决来自私有Artifactory的依赖关系 - artifactory-maven-plugin: How to resolve dependencies from private Artifactory without settings.xml 没有版本,Artifactory无法解决插件工件 - Artifactory cannot resolve plugin artifact without version Maven Bnd 存储库插件无法从远程工件获取工件 - Maven Bnd Repository Plugin fails to fetch artifact from remote artifactory 使Artifactory插件与Jenkins和Maven一起使用 - Getting Artifactory Plugin to work with Jenkins and Maven 从香草Maven切换到Jenkins Artifactory插件后出现“未授权”错误 - 'Not authorized' errors after switching from vanilla Maven to Jenkins Artifactory Plugin Jenkins Artifactory插件忽略了Maven UniqueVersion - Jenkins Artifactory Plugin ignoring Maven UniqueVersion 我如何在使用Maven为Linux上的Jenkins编译cobertura-plugin时解决丢失的工件 - How do i resolve missing artifact while using maven to compile cobertura-plugin for Jenkins on linux Jenkins Artifactory Plugin AQL下载最新神器匹配模式 - Jenkins Artifactory Plugin AQL download latest artifact matching pattern
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM