简体   繁体   中英

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.

I have the Jenkins Credentials Plugin and the Jenkins Artifactory Plugin.

I have added my Artifactory credentials in the Credentials config.

I have configured the Artifactory plugin to use the Credentials and have set up the server 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.

My Jenkins project build is configured to do a 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 .

However, in my Jenkins job, I want to use the Artifactory plugin and the Credentials int he Credentials plugin. 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.

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. That uses the Maven Deploy Plugin, and hence will try to use credentials stored in the settings.xml file.

Instead, use mvn install as the main build task, and set up a new post-build task to Deploy Artifact to Repository.

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. Executing the command

mvn deploy

again for the same version would also result in the

Return code is: 401, ReasonPhrase: Unauthorized.

You can try updating the version to xya which has never been deployed, the job should just run fine.


More from the documentation at Maven Lifecycle Basics

deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

and assuming that you understand What exactly is a Maven Snapshot and why do we need it? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM