git 在 Visual studio 在线构建代理上获取标签

git fetch tags on Visual studio online build agent

我正在使用 Visual Studio 联机 Git 并在我控制的 VM 上使用构建代理 运行 设置了连续构建。

我添加了一个 PowerShell 脚本步骤来在版本化提交上构建 msi 文件,这意味着它们有一个标签。问题是在第一步(Visual studio)中同步 repo 时,不会自动获取标签。

我以为我可以通过在 PowerShell 脚本的开头添加 "git fetch --tags" 来解决这个问题,但这会打印出这个错误:

[error]bash: /dev/tty: No such device or address
[error]error: failed to execute prompt script (exit code 1)
[error]fatal: could not read Username for 'https://myaccount.visualstudio.com': Invalid argument

当我设置构建代理时,它创建了一个访问令牌,但显然没有使用它,它提示输入 username/password。

有人知道如何解决这个问题吗?

Git Build Tools,VSTS 的扩展,它提供了两个新的构建任务以使用 VSTS 提供的 OAuth 令牌重写远程 URL(您需要在构建时启用它定义)。使用这种方法,您不需要在构建代理上使用特定的服务用户帐户和凭据管理器。

  • 在您的 VSTS 扩展中安装 Git Build Tools 扩展。
  • 首先您需要确保在构建定义选项集中有 Allow Scripts to Access OAuth Token 选项。
  • 然后您可以添加 Enable Git Remote Access 任务来重写代理上 Git 存储库的远程,以允许访问 Visual Studio Team Services 上的上游存储库。
  • 在 运行 需要访问远程存储库的操作之后,确保使用 Restore Git Remote 任务将远程存储库恢复为默认值。

您可以找到完整的源代码 here and further documentation in the wiki