描述:
我在尝试使用 Azure DevOps 管道将 NuGet 包发布到 Azure Artifacts 源时遇到错误。我收到的错误消息如下:
at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
##[error]The nuget command failed with exit code(1) and error(Unable to load the service index for source https://pkgs.dev.azure.com/<<organization>>/<<feed>>/nuget/v3/index.json.
Response status code does not indicate success: 400 (Bad Request).
背景:
YAML管道配置如下:
trigger:
branches:
include:
- develop
pool:
vmImage: 'windows-latest'
variables:
packageVersion: '1.0.$(Build.BuildId)'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '8.x'
- script: |
dotnet restore
displayName: 'Restore NuGet packages'
- script: |
dotnet build --configuration Release
displayName: 'Build project'
- script: |
dotnet pack --configuration Release --version-suffix $(packageVersion) --output $(Build.ArtifactStagingDirectory)
displayName: 'Create NuGet package'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- task: NuGetCommand@2
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
publishVstsFeed: 'https://pkgs.dev.azure.com/<<organization>>/<<feed>>/nuget/v3/index.json'
apiKey: '$(System.AccessToken)'
displayName: 'Push NuGet package to Azure Artifacts'
问题:
该错误表明对 NuGet feed 的请求返回了 400(错误请求)状态代码,并带有消息:
Unable to load the service index for source https://pkgs.dev.azure.com/<<organization>>/<<feed>>/nuget/v3/index.json.
Response status code does not indicate success: 400 (Bad Request).
问题:
如何解决此授权错误并成功发布我的 NuGet 包?我是否应该检查其他检查或配置来解决此问题?
提前感谢您的帮助!
我在 Azure DevOps 中配置了 YAML 管道,以恢复、构建、打包 NuGet 包并将其发布到 Azure Artifacts 源。我预计 NuGetCommand@2 任务能够成功地将包推送到源而不会出现错误。但是,该过程失败并出现 400 Bad Request 错误,表明加载指定提要 URL 的服务索引时出现问题。
尝试在管道顶部添加 NuGetAuthenticate@1 任务。
此任务将配置 NuGet 工具以通过 Azure Artifacts 以及最终其他 NuGet 存储库进行身份验证。
使用单个服务连接:
- task: NuGetAuthenticate@1
inputs:
nuGetServiceConnections: myServiceConnection
使用多个服务连接:
- task: NuGetAuthenticate@1
inputs:
nuGetServiceConnections: myServiceConnection, ThirdPartyFeedConnection