我有一个Azure DevOps项目(只有一个)。
我有一个Build Pipeline设置为在“Hosted VS2017”代理池中运行。此代理池似乎位于[MyProject] \ Build Administrators,Contributors,Project Administrators和Release Administrators角色中。
我在DevOps项目中也有一个Artifacts nuget feed。它有[MyProject] \ Project Valid Users设置为“Reader”角色。 Project Valid Users似乎将上面提到的所有Agent Pool角色都作为成员。
我有一个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).
我该怎么做才能做到这一点?我的构建需要来自该工件Feed的其他构建的包......
使用dotnet任务的恢复命令。如果您使用的是单个Azure工件源,只需从任务的下拉列表中选择它(而不是您提到的PowerShell)。如果有多个提要(在您的问题中看起来不像,但为了以防万一),您需要签入引用所有这些提要的NuGet.config,然后将任务指向该配置。
您可能还需要将'--no-restore'标志传递给'dotnet build'命令。
如果您仍然遇到问题,请确保correct build identity可以访问您的Feed。
使用built-in tasks安装和运行NuGet,您将不会遇到身份验证问题。