Azure Pipelines 托管代理无法访问 DevOps 项目源

Jef*_*eff 4 azure-devops azure-pipelines-build-task azure-pipelines azure-artifacts

我有一个 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"'
Run Code Online (Sandbox Code Playgroud)

构建 yml 然后点 adotnet 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).
Run Code Online (Sandbox Code Playgroud)

我怎样才能使这项工作?我的构建需要来自该工件提要上的其他构建的包...

ibe*_*dev 7

有一个更好的替代imo。您可以继续使用您的脚本来dotnet restore. 只需在此之前添加一个任务NuGetAuthenticate@0

steps:
- task: NuGetAuthenticate@0
- script: dotnet restore --no-cache --force
Run Code Online (Sandbox Code Playgroud)

此任务将使用需要这样做并在NuGet.config文件中找到的 nuget 提要对管道进行身份验证。

更多信息在这里

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

  • 非常感谢,我花了几个小时寻找如何拥有 Azure Artifacts 私人源和本地公共源。验证完美完成工作 (3认同)