【问题标题】:Azure Pipelines Hosted Agent Can't Access DevOps project FeedAzure Pipelines 托管代理无法访问 DevOps 项目源
【发布时间】:2019-02-20 21:27:32
【问题描述】:

我有一个 Azure DevOps 项目(只有一个)。

我有一个构建管道设置为在“托管 VS2017”代理池中运行。此代理池似乎具有 [MyProject]\Build Administrators、Contributors、Project Administrators 和 Release Administrators 角色。

我在 DevOps 项目中还有一个 Artifacts nuget 提要。它具有 [MyProject]\Project Valid Users 设置为“读者”角色。项目有效用户似乎具有上述代理池的所有成员角色。

我有一个 azure-pipelines.yml 脚本,它在开头添加了工件提要作为 nuget 源:

# Add nuget source
- powershell: Invoke-RestMethod "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "$env:UserProfile/nuget.exe"
- script: '%UserProfile%\nuget.exe sources Add -Name "devops" -Source "https://pkgs.dev.azure.com/MyProject/_packaging/feed/nuget/v3/index.json"'

构建 yml 然后点一个 dotnet build 但在 NuGet.targets 内部失败:

Unable to load the service index for source https://pkgs.dev.azure.com/MyProject/_packaging/feed/nuget/v3/index.json.
Response status code does not indicate success: 401 (Unauthorized).

我怎样才能做到这一点?我的构建需要来自该工件提要上的其他构建的包...

【问题讨论】:

    标签: azure-devops azure-pipelines azure-pipelines-build-task azure-artifacts


    【解决方案1】:

    imo 有更好的选择。您可以继续使用您的脚本到dotnet restore。 只需在之前添加一个任务NuGetAuthenticate@0

    steps:
    - task: NuGetAuthenticate@0
    - script: dotnet restore --no-cache --force
    

    此任务将使用 nuget 提要对管道进行身份验证,这些提要位于 NuGet.config 文件中。

    More info here

    请注意,当 nuGet 源在 Azure DevOps 中时,不需要其他任何东西。如果源是外部的,您可以在您的 Azure DevOps 中配置一个 nuGet 服务连接(在链接中有更多信息)。

    【讨论】:

    • 非常感谢,一直在寻找如何拥有 Azure Artifacts 私有源和本地公共源的 HOURS 时间。验证完美地完成工作
    【解决方案2】:

    使用built-in tasks 安装和运行 NuGet,您不会遇到身份验证问题。

    【讨论】:

    • dotnet build 不使用 nuget 命令行进行还原,并且 dotnet restore 的行为无法通过仅运行 nuget restore 来重现。我如何能够为此使用 nuget 任务?
    【解决方案3】:

    使用dotnet 任务的恢复命令。如果您使用的是单个 Azure Artifacts 源,只需从任务的下拉列表中选择它(而不是您提到的 PowerShell)。如果有多个提要(从您的问题看不像,但以防万一),您需要签入引用所有这些提要的 NuGet.config,然后将任务指向该配置。

    您可能还需要将“--no-restore”标志传递给“dotnet build”命令。

    如果您仍然遇到问题,请确保 correct build identity 可以访问您的提要。

    【讨论】:

    • 我不明白您所说的“只需从任务的下拉菜单中选择它”是什么意思。为什么 dotnet restore 的行为与实际上只是进行隐式还原的 dotnet build 不同?
    • 现在,告诉 dotnet 一个经过身份验证的提要的唯一方法(即创建一个 nuget.config,其中包含带有构建访问令牌的 <password> 字段)是使用 dotnetnuget 任务的restore 命令。我们积压了一个“NuGet 身份验证”任务,该任务将生成该配置并将其留在磁盘上供您用作dotnet builddotnet restore 的脚本调用的一部分。
    • 为什么 dotnet restore 有效,但 dotnet build 集成恢复无效?我的理解是,它们的工作方式几乎相同
    • $env:SYSTEM_ACCESSTOKEN 不适合我的目的吗?
    • dotnet restoredotnet build 调用相同的代码进行恢复。不同之处在于 VSTS dotnet 任务的当前实现,它仅在您选择“恢复”步骤时提供经过正确身份验证的 NuGet.config。
    猜你喜欢
    • 1970-01-01
    • 2021-01-25
    • 2021-11-14
    • 2020-12-12
    • 2020-01-14
    • 1970-01-01
    • 2020-06-03
    • 2021-01-05
    • 2020-10-28
    相关资源
    最近更新 更多