【问题标题】:NuGet Push Results in 401 Unauthorized Error within TFS Build and on TFS Server ItselfNuGet 推送导致 TFS 内部和 TFS 服务器本身出现 401 未经授权的错误
【发布时间】:2018-02-02 15:19:15
【问题描述】:

NuGet Push 在 TFS 构建和 TFS 服务器本身上导致 401 未经授权的错误

我们正在从 BitBucket、Jenkins 和 Nexus 过渡到 TFS 2018 以容纳我们的 Git 存储库、不断集成我们的 C# 代码并存储我们的构建工件。我们正在 TFS 服务器上添加我们的第一个构建定义,并且我们的构建定义(如下)成功,直到我们进入 NuGet 推送步骤。

  1. 获取源 - 从同一 TFS 服务器克隆 Git 存储库
  2. NuGet 工具安装程序(版本 0.*) - 安装 NuGet 4.3.0
  3. 下载文件(版本 1.*) - 下载一个可执行 JAR 以在构建过程中使用(更多信息请参见底部)。
  4. NuGet(版本 2.*) - 在我们的解决方案中恢复 NuGet 包
  5. Powershell(版本 1.*) - 调用 JAR 以在我们的 .nuspec 文件中填充 NuGet 包步骤的依赖项。
  6. Powershell(版本 1.*) - 调用 JAR 以增加修订版本号(更多信息请参见底部)。
  7. MSBuild(版本 1.*) - 构建解决方案
  8. Powershell(版本 1.*) - 调用 JAR 以增加构建和次要版本号(更多信息请参见底部)。
  9. NuGet(版本 1.*) - 打包 NuGet 包
  10. NuGet(版本 1.*) - 将 NuGet 包推送到 TFS 上的 NuGet 源
  11. Powershell(版本 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 提要,如您所见 here

但是,我们甚至尝试了“外部 NuGet 服务器(包括其他帐户/集合)”选项(上图中红色轮廓的右侧),我们将 URL 添加到 NuGet 提要和我的 PAT 凭据中我本周早些时候创建的,我们遇到了同样的错误。

有趣的是,每当我在我的计算机上调用nuget push 命令Powershell,并使用我的用户名和PAT 传入相同的.nupkg 文件时,它都能够毫无问题地推送;当我尝试通过远程桌面连接到 TFS 服务器来执行相同操作时,会出现同样的问题。

还有其他人遇到过这个问题吗?有没有人可以解决这个问题或者可以帮助我们走上正确的道路?


关于可执行 JAR 的注意事项:在我们的构建过程中,我们调用一个 Powershell 脚本,该脚本收集附加参数以作为命令行参数传递给可执行 JAR。然后,当我们的构建中的一个阶段完成时,JAR 使用此信息来增加我们的版本号的一部分,它遵循 major.minor.build.revision 格式。过去几个月我们一直在 Jenkins 上使用这个 JAR,它并没有影响我们将可用的 NuGet 包推送到我们的 Nexus 存储库的能力。

【问题讨论】:

    标签: nuget azure-artifacts


    【解决方案1】:

    请尝试以下项目来缩小问题范围:

    1. 确认在您的 TFS AT 上禁用了 IIS 基本身份验证。

      在启用 IIS 基本身份验证时,通过 nuget.exe 等基本身份验证发送的令牌在这些任务中使用将不起作用。有点混乱,但基本上 IIS 会干扰 TFS 验证基本凭据的能力。

      详情参考本文:Enabling IIS Basic Authentication invalidates using Personal Access Tokens

    2. 尝试以“普通”用户身份运行构建代理(设置您自己的使用 帐户作为构建代理服务帐户)

    详情请参阅此类似主题: NuGet Publisher build task fails with errors 401 (Unauthorized) and 402 (Payment Required)

    【讨论】:

    • 谢谢@Andy 的回复。尽管我们曾一度启用了基本身份验证,但后来我们禁用了它。即使禁用它并在 IIS 管理器中验证它已被禁用,我们仍然遇到这个问题。为了完全禁用基本身份验证,我们是否必须完成其他一些步骤?在 IIS 中,启用“匿名身份验证”和“Windows 身份验证”,禁用“ASP.NET 模拟”和“表单身份验证”。
    • @AHuber 没有其他步骤,只是禁用基本身份验证。第二种方式呢?只需将您的具有正确访问 NuGet 服务器权限的帐户设置为构建代理服务帐户即可。
    • #2 是问题所在!构建代理作为“网络服务”登录,但一旦我将用户更改为我自己并仔细检查我是否有权推送到 TFS NuGet 提要,随后的构建成功并推送了 NuGet 包。非常感谢您的帮助!
    • 感谢您的回答! #1 是我们的情况 - 我们启用了基本身份验证,以便将自定义扩展部署到本地 TFS 实例。
    猜你喜欢
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    • 2011-11-18
    • 2021-12-02
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多