问题描述
我正在尝试在 azure devops 服务器上创建构建管道,我的构建管道能够从 Azure Artifact 下载依赖项
2021-03-02T05:45:24.8329366Z [INFO] ------------------------------------------------------------------------
2021-03-02T05:45:24.8329608Z [INFO] Total time: 02:31 min
2021-03-02T05:45:24.8330187Z [INFO] Finished at: 2021-03-02T05:45:24Z
2021-03-02T05:45:24.8330469Z [INFO] ------------------------------------------------------------------------
2021-03-02T05:45:24.8330824Z [ERROR] Failed to execute goal on project myapplication-commons-lib: Could not resolve dependencies for project com.myapplication.mdm.commons:myapplication-commons-lib:jar:1.0.0-SNAPSHOT: Failed to collect dependencies at com.tibco.ebx.core:ebx-lib:jar:5.9.10: Failed to read artifact descriptor for com.tibco.ebx.core:ebx-lib:jar:5.9.10: Could not transfer artifact com.tibco.ebx.core:ebx-lib:pom:5.9.10 from/to myapp-snapshots (https://myapplication.pkgs.visualstudio.com/_packaging/myapp-snapshots/maven/v1): Authentication Failed for https://myapplication.pkgs.visualstudio.com/_packaging/myapp-snapshots/maven/v1/com/tibco/ebx/core/ebx-lib/5.9.10/ebx-lib-5.9.10.pom 401 Unauthorized -> [Help 1]
2021-03-02T05:45:24.8331113Z [ERROR] ```
YAML Pipeline
[![enter image description here][1]][1]
[![enter image description here][2]][2]
[1]: https://i.stack.imgur.com/L34oP.png
YAML from pipeline
- task: Maven@3
displayName: 'Code Compilation'
inputs:
mavenPomFile: '$(System.DefaultWorkingDirectory)/solution/core/build/maven/pom.xml'
options: '-s $(System.DefaultWorkingDirectory)/solution/core/build/maven/settings.xml'
goals: package
mavenAuthenticateFeed: true
解决方法
....401 未经授权
401 错误是身份验证错误。
在调用 Maven 任务之前添加 Maven Authenticate task。 Maven Authenticate 任务可以为当前用户的 settings.xml 文件中的 Azure Artifacts 源和外部 Maven 存储库提供凭据。
如果你的天蓝色神器在同一个集合中,你可以直接在下拉列表中选择对应的提要。
如果您是外部 azure 工件(例如 Azure Devops 服务),则需要在 Porject Settings -> Service Connections 中创建服务连接(maven)。
更新:
如果您无法使用 Maven Authenticate 任务,您可以尝试以下步骤来使用 Settings.xml 文件。
第一步:创建一个 Setting.xml 文件。
您可以导航到 Azure Devops Service -> Artifacts -> Connect to feed -> Maven。
第 2 步:在 Azure Devops 服务器中,您可以将 settings.xml 保存到路径
%USERPROFILE%\.m2\settings.xml
您可以参考this doc。
另一方面,当您向 Maven 任务添加选项时。
例如:
- task: Maven@3
displayName: 'Maven pom.xml'
inputs:
...
options: '-s filepath/settings.xml'