[英]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.我正在尝试为使用 Maven 的 Java 项目创建一个简单的管道。 The .jar dependencies of my project are all hosted on an online Nexus that is password protected.
我的项目的 .jar 依赖项都托管在受密码保护的在线 Nexus 上。 The sources I am building are hosted on Bitbucket.
我正在构建的源代码托管在 Bitbucket 上。
I can't seem to find how to tell the pipeline what credentials to use for Nexus.我似乎无法找到如何告诉管道将哪些凭据用于 Nexus。
This is my maven task result:这是我的 Maven 任务结果:
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?
当我从我自己的机器在本地运行构建时,它确实可以工作,因为我的 .m2 文件夹中有一个 settings.xml 文件,其中包含凭据,但如何使其从 Azure DevOps 工作?
You can have a try using Maven Authenticate task add a maven service connection to connect to your external maven repositories.您可以尝试使用Maven Authenticate任务添加一个 Maven 服务连接来连接到您的外部 Maven 存储库。 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.
转到项目设置-->管道--> 单击服务连接--> 单击新服务连接--> 选择Maven --> 输入 Nexus 存储库所需的信息。
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.
然后在你的管道加入Maven的身份验证任务Maven的任务之前做出规定,这将在以下Maven任务中使用的外部Maven仓库的凭证。
Since you only need authentication for external nexus maven repositories, you can leave Feeds field blank.由于您只需要对外部 nexus maven 存储库进行身份验证,因此您可以将Feeds字段留空。 And Then click below highlighted dropdown list to select the maven service connection for nexus you created in above steps.
然后单击下面突出显示的下拉列表,为您在上述步骤中创建的 nexus 选择 Maven 服务连接。
When you finish above steps, your maven task should be able to download jar dependencies from nexus.完成上述步骤后,您的 maven 任务应该能够从 nexus 下载 jar 依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.