【问题标题】:How to specify credentials for external nuget feeds in VSTS nuget restore如何在 VSTS nuget restore 中为外部 nuget 提要指定凭据
【发布时间】:2018-03-29 09:57:14
【问题描述】:

我正在使用 VSTS 中的内置 nuget 任务来执行包还原。我们的提要托管在内部 Artifactory 服务器上,并在我的 nuget.config 中作为包源引用。然后,我在 VSTS 中使用 nuget 服务端点来存储访问该提要的凭据。

但是当我运行构建时,我会在构建日志中看到以下内容,并且对 nuget 提要的每个请求都会导致 401 Unauthorized。

CredentialProvider.TeamBuild: URI Prefixes:
CredentialProvider.TeamBuild:     https://ukipo.visualstudio.com/
CredentialProvider.TeamBuild:     https://ukipo.pkgs.visualstudio.com/
CredentialProvider.TeamBuild: URI: http://repo1:8081/artifactory/api/nuget/nuget-repos
CredentialProvider.TeamBuild: Is retry: False
CredentialProvider.TeamBuild: Matched prefix: 
CredentialProvider.TeamBuild: This provider only handles URIs from the build's Team Project Collection

Unauthorized http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages(Id='Microsoft.AspNet.Razor',Version='3.2.3') 16ms
WARNING: Unable to find version '3.2.3' of package 'Microsoft.AspNet.Razor'.
  http://repo1:8081/artifactory/api/nuget/nuget-repos: The V2 feed at 'http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages(Id='Microsoft.AspNet.Razor',Version='3.2.3')' returned an unexpected status code '401 Unauthorized'.

我还需要配置其他什么来获取在服务端点中获取凭据的任务吗?如果我只是将它们作为 packageSourceCredentials 放在 nuget.config 中,一切正常。

【问题讨论】:

    标签: nuget azure-devops azure-pipelines


    【解决方案1】:

    由于 nuget 软件包提要位于内部服务器中,您应该使用 private build agent,它可以访问 URL http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages

    当你执行 NuGet 还原任务时,有两个选项可以添加 nuget feed 凭据:

    选项1:按你使用的方式使用nuget服务端点

    您可以使用基本身份验证添加 Nuget 端点。输入feed URL、用户名和密码后,请在保存前验证连接。

    选项 2:在您的 nuget.config 文件中添加凭据

    在您的本地仓库中,您可以将凭证添加到您的项目级别 nuget.config 文件,如下命令:

    nuget sources add -name "nuget-repos" -source "http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages" -username "username" -password "password" -ConfigFile path\to\project\.nuget\nuget.config
    

    然后您可以提交并将更改推送(签入)到远程仓库,并在不指定 nuget 服务端点的情况下进行构建。

    注意:

    【讨论】:

    • 谢谢,选项 1 有效。我正在使用失败的 API 密钥选项,但基本身份验证似乎工作正常。其他尝试此操作的人请注意 - 如果您的提要只能在内部访问,则“验证连接”选项将不起作用,但它仍可通过内部代理工作。
    • 如果我对 API 密钥 : 使用以下格式,则使用 API 密钥对我有用。在 API 密钥之前附加用户名和冒号就可以了。
    • 不再有使用任何身份验证方法在 ADO 中验证您的连接的选项。
    猜你喜欢
    • 2018-09-12
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多