NuGet 推送导致 TFS 内部和 TFS 服务器本身出现 401 未经授权的错误
我们正在从 BitBucket、Jenkins 和 Nexus 过渡到 TFS 2018,以容纳我们的 Git 存储库,不断集成我们的 C# 代码,并存储我们的构建工件。我们正在我们的 TFS 服务器上添加我们的第一个构建定义,并且我们的构建定义(如下)成功,直到我们进入 NuGet 推送步骤。
- 获取源- 从同一 TFS 服务器克隆 Git 存储库
- NuGet 工具安装程序(版本 0.*) - 安装 NuGet 4.3.0
- 下载文件(版本 1.*) - 下载在构建过程中使用的可执行 JAR(有关更多信息,请参见底部)。
- NuGet(版本 2.*) - 在我们的解决方案中恢复 NuGet 包
- Powershell(版本 1.*) - 调用 JAR 以在我们的
.nuspec
文件中填写 NuGet 包步骤的依赖项。 - Powershell (Version 1.*) - 调用 JAR 来增加修订版本号(更多信息请参见底部)。
- MSBuild(版本 1.*) - 构建解决方案
- Powershell (Version 1.*) - 调用 JAR 来增加构建和次要版本号(更多信息请参见底部)。
- NuGet(版本 1.*) - 打包 NuGet 包
- NuGet(版本 1.*) - 将 NuGet 包推送到 TFS 上的 NuGet 源
- Powershell (Version 1.*) - 调用 JAR 将最终版本号存储在服务器上,以便在将来的构建中使用(更多信息请参见底部)。
当我们进入推送 NuGet 包的第 10 步时,我们收到以下错误,即使项目构建服务是 NuGet 提要上的“所有者”,并且构建定义的项目授权范围设置为“项目集合” 。”
2018-02-01T15:55:20.2291785Z ##[section]Starting: NuGet push
2018-02-01T15:55:20.2291785Z ==============================================================================
2018-02-01T15:55:20.2291785Z Task : NuGet
2018-02-01T15:55:20.2291785Z Description : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Package Management and MyGet.
2018-02-01T15:55:20.2291785Z Version : 2.0.7
2018-02-01T15:55:20.2291785Z Author : Microsoft Corporation
2018-02-01T15:55:20.2291785Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613747)
2018-02-01T15:55:20.2291785Z ==============================================================================
2018-02-01T15:55:20.9633816Z [command]C:\WINDOWS\system32\chcp.com 65001
2018-02-01T15:55:21.0259411Z Active code page: 65001
2018-02-01T15:55:21.0416108Z SYSTEMVSSCONNECTION exists true
2018-02-01T15:55:21.0727651Z Detected NuGet version 4.3.0.4406 / 4.3.0
2018-02-01T15:55:21.1509681Z Saving NuGet.config to a temporary config file.
2018-02-01T15:55:21.1668061Z ##[warning]No package sources were found in the NuGet.config file at C:\agent\_work\5\Nuget\tempNuGet_178.config
2018-02-01T15:55:21.1821145Z [command]C:\agent\_work\_tool\NuGet\4.3.0\x64\nuget.exe push C:\agent\_work\5\a\{name_of_our_nuget_package}.nupkg -NonInteractive -Source https://{tfs_server_location}/Mobile%20Applications/_packaging/a4a3b7fe-b530-4e51-b8c2-3ee73ede20da/nuget/v3/index.json -ApiKey VSTS -Verbosity Detailed
2018-02-01T15:55:21.7455077Z NuGet Version: 4.3.0.4406
2018-02-01T15:55:22.1513242Z CredentialProvider.TeamBuild: "C:\agent\_work\_tasks\NuGetCommand_333b11bd-d341-40d9-afcf-b32d5ce6f23b\2.0.7\node_modules\nuget-task-common\NuGet\CredentialProvider\CredentialProvider.TeamBuild.exe" -uri https://{tfs_server_location}/Mobile Applications/_packaging/a4a3b7fe-b530-4e51-b8c2-3ee73ede20da/nuget/v3/index.json -nonInteractive -verbosity detailed
2018-02-01T15:55:22.1513242Z CredentialProvider.TeamBuild: URI Prefixes:
2018-02-01T15:55:22.1513242Z CredentialProvider.TeamBuild: https://{tfs_server_location}/Mobile Applications/
2018-02-01T15:55:22.1513242Z CredentialProvider.TeamBuild: URI: https://{tfs_server_location}/Mobile
2018-02-01T15:55:22.1513242Z CredentialProvider.TeamBuild: Is retry: False
2018-02-01T15:55:22.1513242Z CredentialProvider.TeamBuild: Matched prefix:
2018-02-01T15:55:22.3854366Z CredentialProvider.TeamBuild: This provider only handles URIs from the build's Team Project Collection
2018-02-01T15:55:22.7448581Z Unable to load the service index for source https://{tfs_server_location}/Mobile%20Applications/_packaging/a4a3b7fe-b530-4e51-b8c2-3ee73ede20da/nuget/v3/index.json.
2018-02-01T15:55:22.7448581Z Response status code does not indicate success: 401 (Unauthorized).
2018-02-01T15:55:22.7610511Z NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://{tfs_server_location}/Mobile%20Applications/_packaging/a4a3b7fe-b530-4e51-b8c2-3ee73ede20da/nuget/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
2018-02-01T15:55:22.7610511Z at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.HttpSource.<>c__DisplayClass12_0`1.<<GetAsync>b__0>d.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Common.ConcurrencyUtilities.<ExecuteWithFileLockedAsync>d__2`1.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.HttpSource.<GetAsync>d__12`1.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.ServiceIndexResourceV3Provider.<GetServiceIndexResourceV3>d__9.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of inner exception stack trace ---
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.ServiceIndexResourceV3Provider.<GetServiceIndexResourceV3>d__9.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.ServiceIndexResourceV3Provider.<TryCreate>d__8.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.Core.Types.SourceRepository.<GetResourceAsync>d__16`1.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.PackageUpdateResourceV3Provider.<TryCreate>d__1.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.Core.Types.SourceRepository.<GetResourceAsync>d__16`1.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Protocol.Core.Types.SourceRepository.<GetResourceAsync>d__15`1.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Commands.CommandRunnerUtility.<GetPackageUpdateResource>d__3.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.Commands.PushRunner.<Run>d__0.MoveNext()
2018-02-01T15:55:22.7610511Z --- End of stack trace from previous location where exception was thrown ---
2018-02-01T15:55:22.7610511Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-02-01T15:55:22.7610511Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-02-01T15:55:22.7610511Z at NuGet.CommandLine.PushCommand.<ExecuteCommandAsync>d__28.MoveNext()
2018-02-01T15:55:22.7916018Z ##[error]Error: C:\agent\_work\_tool\NuGet\4.3.0\x64\nuget.exe failed with return code: 1
2018-02-01T15:55:22.7916018Z ##[error]Packages failed to publish
2018-02-01T15:55:22.8228295Z ##[section]Finishing: NuGet push
最初,我们试图通过选择 NuGet 推送构建步骤中“目标提要位置”部分下的“此帐户/集合”选项将 NuGet 包推送到 TFS 提要,如您在此处看到的。
但是,我们甚至尝试了“外部 NuGet 服务器(包括其他帐户/集合)”选项(上图中红色轮廓的右侧),我们将 URL 添加到 NuGet 提要和我的凭据以及我之前创建的 PAT本周,我们遇到了同样的错误。
有趣的是,每当我nuget push
在我的计算机上调用命令 Powershell 并.nupkg
使用我的用户名和 PAT 传入同一个文件时,它都能够毫无问题地推送;当我尝试通过远程桌面连接到 TFS 服务器来执行相同操作时,会出现同样的问题。
有没有其他人遇到过这个问题?有没有人可以解决这个问题或者可以帮助我们走上正确的道路?
关于可执行 JAR 的注意事项:在我们的构建过程中,我们调用一个 Powershell 脚本,该脚本收集附加参数以作为命令行参数传递给可执行 JAR。然后,当我们的构建中的一个阶段完成时,JAR 使用此信息来增加我们的版本号的一部分,它遵循major.minor.build.revision格式。在过去的几个月里,我们一直在 Jenkins 上使用这个 JAR,它并没有影响我们将可用的 NuGet 包推送到我们的 Nexus 存储库的能力。