Azure管道不能与Github软件包一起使用

时间:2020-08-09 00:03:14

标签: azure-devops azure-pipelines github-package-registry

非常容易复制:

          - task: NuGetCommand@2
            displayName: NuGet push
            inputs:
              command: 'push'
              packagesToPush: '$(Pipeline.Workspace)/**/*.nupkg'
              nuGetFeedType: 'external'
              externalFeedCredentials: 'github-packages'
              publishFeedCredentials: 'github-packages'
              allowPackageConflicts: true

github-packages是项目中的NuGet服务连接,使用的PAT具有对我的GitHub组织的完全访问权限。

我在日志中看到以下输出

2020-08-08T23:48:41.3089867Z [command]"C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/msbuild.exe" /version /nologo
2020-08-08T23:48:42.7276911Z Caching tool: NuGet 5.4.0 x64
2020-08-08T23:48:42.7397600Z Found tool in cache: NuGet 5.4.0 x64
2020-08-08T23:48:42.7452624Z Resolved from tool cache: 5.4.0
2020-08-08T23:48:42.7453195Z Using version: 5.4.0
2020-08-08T23:48:42.7465530Z Found tool in cache: NuGet 5.4.0 x64
2020-08-08T23:48:42.8246178Z SYSTEMVSSCONNECTION exists true
2020-08-08T23:48:43.1624000Z SYSTEMVSSCONNECTION exists true
2020-08-08T23:48:43.8522322Z [command]C:\windows\system32\chcp.com 65001
2020-08-08T23:48:43.8632712Z Active code page: 65001
2020-08-08T23:48:44.2527739Z SYSTEMVSSCONNECTION exists true
2020-08-08T23:48:44.2733846Z Detected NuGet version 5.4.0.6315 / 5.4.0+d790b66be476cd901a56bd46ada037162097ee21.d790b66be476cd901a56bd46ada037162097ee21
2020-08-08T23:48:44.2752584Z 1b529ea0-989d-42e8-af13-8ba56ff0e7d8 exists true
2020-08-08T23:48:44.2836605Z [command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe sources Add -NonInteractive -Name httpsnugetpkggithubcomourorgindexjson -Source https://nuget.pkg.github.com/ourorg/index.json -ConfigFile d:\a\1\Nuget\tempNuGet_3286.config
2020-08-08T23:48:45.7706128Z Package source with Name: httpsnugetpkggithubcomourorgindexjson added successfully.
2020-08-08T23:48:45.7804645Z Using authentication information for the following URI: https://nuget.pkg.github.com/ourorg/index.json
2020-08-08T23:48:45.8355905Z [command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe setapikey *** -NonInteractive -Source httpsnugetpkggithubcomourorgindexjson -ConfigFile d:\a\1\Nuget\tempNuGet_3286.config
2020-08-08T23:48:46.4520785Z The API Key '***' was saved for 'https://nuget.pkg.github.com/ourorg/index.json'.
2020-08-08T23:48:46.4686061Z [command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe push d:\a\1\Build\M365Management.Console.0.2.83.nupkg -NonInteractive -Source https://nuget.pkg.github.com/ourorg/index.json -ApiKey *** -ConfigFile d:\a\1\Nuget\tempNuGet_3286.config -Verbosity Detailed
2020-08-08T23:48:49.1593595Z Unable to load the service index for source https://nuget.pkg.github.com/ourorg/index.json.
2020-08-08T23:48:49.1594103Z NuGet Version: 5.4.0.6315
2020-08-08T23:48:49.1594906Z   Response status code does not indicate success: 401 (Unauthorized).
2020-08-08T23:48:49.1595523Z Using d:\a\_tasks\NuGetCommand_333b11bd-d341-40d9-afcf-b32d5ce6f23b\2.172.0\CredentialProviderV2\plugins\netfx\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe as a credential provider plugin.
2020-08-08T23:48:49.1596753Z NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://nuget.pkg.github.com/ourorg/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).

问题似乎在这里:

...nuget.exe sources Add -NonInteractive -Name httpsnugetpkggithubcomourorgindexjson -Source https://nuget.pkg.github.com/ourorg/index.json -ConfigFile d:\a\1\Nuget\tempNuGet_3286.config

它将外部供稿添加为源,但添加时不使用Service Connection api键。它仅在push命令中使用api键...因此尝试在https://nuget.pkg.github.com/ourorg/index.json

处查询源时失败。

我猜想这只是Azure DevOps中另一个破碎的功能,但是希望得到一些确认。

谢谢。

2 个答案:

答案 0 :(得分:0)

您可能需要使用Basic Authentication作为Nuget服务连接的身份验证方法。在PAT字段中使用您的Password。参见下面的屏幕:

转到项目设置->管道下的服务连接->编辑您的Nuget服务连接->选择Basic Authentication作为身份验证方法->输入您的UserName->输入您的{ PAT字段中的{1}}。

enter image description here

答案 1 :(得分:0)

在您的 nuspec 文件中,您有存储库元素吗?

<repository type="git" url="https://github.com/yourorganization/YourRepo" />

当你进行推送时,使用 ApiKey 代替:ApiKey 应该是一个 PAT,具有写入包的访问权限 enter image description here