azure-devops - Azure DevOps 项目管道无法从不同项目中的工件源访问 NuGet 包

标签 azure-devops azure-pipelines devops nuget-package-restore azure-artifacts

2020 年 2 月 20 日更新

总结

Azure DevOps 管道构建无法从 Artifacts 下的私有(private)源中找到 NuGet 包。

我们的 Azure DevOps 环境

在 Azure 中,我们有我们公司的“空间”:dev.azure.com/OurCompany

在此之下,我们有多个项目,例如,想象一下这三个:

  • 绿色:这包含某种类型的应用程序
  • 蓝色:这包含不同类型的应用程序
  • 红色:这包含我们的“通用”帮助代码

  • 红色

    RED 持有我们所有常见的帮助代码是 GREEN 和 BLUE 应用程序使用的 DLL。这些以 NuGet 包的形式提供。

    在 RED 的 Artifacts 下,我们看到了一个名为“OurCompany”的“组织范围的提要”。我们知道我们不能使用它,因为这些 NuGet 包需要对 OurCompany 中的每个人都可用,这意味着不仅在 Azure 上,而且在我们公司网络中的桌面计算机上(我们运行 Visual Studio 的地方)。我不认为“组织范围的提要”暴露在我们的企业网络中。

    因此,我们在 RED 的 Artifacts 下创建了一个新的 Feed。当我查看权限时,我看到以下条目:
  • {我}:(所有者)
  • [OurCompany]\Project Collection 管理员:(所有者)
  • [RED]\项目管理员:(所有者)
  • RED 构建服务(OurCompany):(贡献者)
  • Project Collection Build Service (OurCompany) : (贡献者)
  • [RED]\Contributors(贡献者)

  • 企业

    因此,回到 Corporate 中,我们将 NuGet 包源添加到 Visual Studio,然后它可以从 Azure 中提取 NuGet 包。

    绿蓝

    在这里,我们有我们的产品。我们创建一个构建管道并添加一个 NuGet 还原步骤:
    - task: NuGetCommand@2
      displayName: 'Restore for Our Application'
      inputs:
        command: 'restore'
        restoreSolution: '**/*.sln'
        feedsToUse: 'select'
        vstsFeed: '{Guid1}/{Guid2}'
    

    当我们从下拉列表中挑选 Azure Artifacts 提要时,这两个 Guid 已被填写。

    绿色或蓝色 NuGet 还原失败

    所以这就是我们遇到问题的地方。当 NuGet 还原步骤执行时,它会失败并显示以下消息:
    Unable to find version 'nnnn.n.n' of package 'TheNuGetPackage'.
    

    日志输出很大,但突出的几行似乎是:
    2020-02-18T18:36:35.2838118Z [command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe sources Add -NonInteractive -Name {Guid2} -Source https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json
    -ConfigFile d:\a\1\Nuget\tempNuGet_356.config 2020-02-18T18:36:35.7513495Z Package source with Name: {Guid2} added successfully. 2020-02-18T18:36:41.1671856Z     [CredentialProvider.183638]Command-line v0.1.20+a5d37185a1a95acb4f0g997b9c23cab99508: "d:\a\_tasks\NuGetCommand_333b11bd-d341-40d9-bdbd-b32d5ce6f23b\2.164.0\CredentialProviderV2\plugins\netfx\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe"
    -Plugin 2020-02-18T18:36:41.1673979Z     [CredentialProvider]Handling 'Request' 'GetAuthenticationCredentials'. Time elapsed in ms: 3 - Payload: {"Uri":"https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json","IsRetry":false,"IsNonInteractive":true,"CanShowDialog":true} 2020-02-18T18:36:41.1674299Z     [CredentialProvider]Handling auth request, Uri: https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json, IsRetry: False, IsNonInteractive: True, CanShowDialog: True 2020-02-18T18:36:41.1674465Z     [CredentialProvider]URI: https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json 2020-02-18T18:36:41.1674818Z     [CredentialProvider]Skipping NuGetCredentialProvider.CredentialProviders.VstsBuildTaskServiceEndpoint.VstsBuildTaskServiceEndpointCredentialProvider, cannot provide credentials for https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json 2020-02-18T18:36:41.1675261Z     [CredentialProvider]VstsBuildTaskCredentialProvider - https://dev.azure.com/OurCompany/ 2020-02-18T18:36:41.1675425Z     [CredentialProvider]VstsBuildTaskCredentialProvider - https://pkgs.dev.azure.com/OurCompany/ 2020-02-18T18:36:41.1675722Z    [CredentialProvider]VstsBuildTaskCredentialProvider - https://pkgs.dev.azure.com/OurCompany/ 2020-02-18T18:36:41.1676021Z    [CredentialProvider]VstsBuildTaskCredentialProvider - https://pkgs.dev.azure.com/OurCompany/ 2020-02-18T18:36:41.1676161Z    [CredentialProvider]VstsBuildTaskCredentialProvider - Matched prefix: https://pkgs.dev.azure.com/OurCompany/ 2020-02-18T18:36:41.1676330Z    [CredentialProvider]VstsBuildTaskCredentialProvider - Found credentials for endpoint https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json 2020-02-18T18:36:41.1680820Z   https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json: Unable to load the service index for source https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json. 2020-02-18T18:36:41.1680996Z   Response status code does not indicate success: 404 (Not Found - VS800075: The project with id 'vstfs:///Classification/TeamProject/{Guid1}' does not exist, or you do not have permission to access it. (DevOps Activity ID: 0628EDE7-6E7E-465D-A6AE-7B6B0AA065D2)).
    

    这对我来说似乎是一个权限问题。但奇怪的是,当我们没有使用它的权限时,在创建管道构建 YAML 时可以发现 RED 中的 Artifact Feed。

    我确实尝试在 RED 中为 Feed 添加权限。单击“添加用户/组”。我找到了以下内容并将它们添加为读者或贡献者,但没有成功。
  • [绿色]\绿色团队
  • 绿色建筑服务

  • 所以:
  • 我会以错误的方式解决这个问题吗?如果是这样,我应该做什么(我以为我已经非常严格地遵循了 Azure DevOps 说明)
  • 我会以正确的方式解决这个问题吗?如果是这样,我错过了什么?

  • 更新 #1

    来自恢复步骤的详细错误消息

    https://api.nuget.org/v3/index.json: Package 'Package1.nnnn.n.n' is not found on source 'https://api.nuget.org/v3/index.json'.
    https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json: Unable to load the service index for source https://pkgs.dev.azure.com/OurCompany/{Guid1}/_packaging/{Guid2}/nuget/v3/index.json. Response status code does not indicate success: 404 (Not Found - VS800075: The project with id 'vstfs:///Classification/TeamProject/{Guid1}' does not exist, or you do not have permission to access it. (DevOps Activity ID: {Guid})).

    最佳答案

    最后,我发现了问题。我想知道这是否是一个错误,或者只是记录不充分......(或者我只是没有正确解释它)。

    根据上面 Leo Lui-MSFT 的建议(由 Microsoft 记录),我已将权限添加到 NuGet 提要,但这不起作用。不过,我对他的一句话很感兴趣:

    If you've changed your builds to run at project scope



    就个人而言,我没有,所以我与我们的系统管理员联系,我们完成了所有可能的设置。最终,我们找到了它——这不是我有能力改变的。

    因此,在我上面的示例中,BLUE 和 GREEN 是尝试在 RED 的 Artifact 提要中使用 NuGet 包的两个项目。

    因此,选择蓝色(或绿色),在 Azure DevOps 的左下角,您将看到一个链接“项目设置”。在“管道 > 设置”下有四个设置。我们必须将以下内容更改为:

    Limit job authorization scope to current project = false



    希望有帮助!

    关于azure-devops - Azure DevOps 项目管道无法从不同项目中的工件源访问 NuGet 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60296233/

    相关文章:

    azure-devops - Azure Devops禁用同一管道上的并发运行

    Azure Devops - 使用脚本访问拉取请求中的构建验证管道的数量

    ubuntu - 不支持 Ubuntu 中的 Docker 将文件系统切换到覆盖?

    Azure pipeline yml - 更改任务中的值并根据 if else 条件执行

    azure - 对组中的用户隐藏 Azure DevOps 中的文件夹名称、板名称和项目设置页面

    azure-devops - Azure Functions V2中的OpenAPI(又名Swagger)

    amazon-web-services - AzureDevOps - YAML 模板的参数问题

    git - 在 Azure DevOps 中发布的 Git 分支未在 VS2013 或 Git 命令行中显示

    bash - 在 Azure Devops 中,如何在 "Azure CLI task v.2"运行的 shell 脚本中使用管道变量?

    linux - 如何让 Jenkins 执行特定文件