简体   繁体   中英

Where do I set the Nexus credentials for an Azure DevOps pipeline on a Maven project hosted on Bitbucket?

I'm trying to create a simple Pipeline for a Java project that uses Maven. The .jar dependencies of my project are all hosted on an online Nexus that is password protected. The sources I am building are hosted on Bitbucket.

I can't seem to find how to tell the pipeline what credentials to use for Nexus.

This is my maven task result:

Downloaded from central: xxx (34 kB at 1.3 MB/s)
Downloading from nexus: xxx
Downloading from central: xxx
Downloading from nexus: xxx
Downloading from central: xxx
Downloading from nexus: xxx
Downloading from central: xxx 949 B

Downloaded from central: xxx (949 B at 45 kB/s)
Downloading from nexus: xxx
Downloading from central: xxx
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.979 s
[INFO] Finished at: 2020-01-16T19:17:43Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project webconfigurable: Could not resolve dependencies for project com.fenplast:webconfigurable:jar:1.3.0: Failed to collect dependencies at org.jscience:com.netappsid.org.jscience:jar:3.2.0: Failed to read artifact descriptor for org.jscience:com.netappsid.org.jscience:jar:3.2.0: Could not transfer artifact org.jscience:com.netappsid.org.jscience:pom:3.2.0 from/to nexus (https://repository.fenplast.net/repository/public): Authentication failed for https://repository.fenplast.net/repository/public/org/jscience/com.netappsid.org.jscience/3.2.0/com.netappsid.org.jscience-3.2.0.pom 401 Unauthorized -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
The process '/usr/share/apache-maven-3.6.3/bin/mvn' failed with exit code 1
Could not retrieve code analysis results - Maven run failed.
No test result files matching /home/vsts/work/1/s/**/surefire-reports/TEST-*.xml were found, so publishing JUnit test results is being skipped.
##[error]Build failed.
Finishing: Maven 

It says Authentication failed and Unauthorized. When I run a build from my own machine locally it does work because I have a settings.xml file in my .m2 folder with the credentials but how do I make it work from Azure DevOps?

You can have a try using Maven Authenticate task add a maven service connection to connect to your external maven repositories. Below steps is for reference.

Go to Project settings --> Pipelines --> Click Service connections --> Click new service connection --> select Maven --> Enter the required information for your Nexus Repository.

在此处输入图片说明

Then in your pipeline Add Maven Authenticate task before your Maven task to provides credentials for the external Maven repositories which will be used in the following maven task.

Since you only need authentication for external nexus maven repositories, you can leave Feeds field blank. And Then click below highlighted dropdown list to select the maven service connection for nexus you created in above steps.

在此处输入图片说明

When you finish above steps, your maven task should be able to download jar dependencies from nexus.

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