Git 构建结束时的标记 Visual Studio 在线(构建 vNext,托管池)

Git tag at the end of build on Visual Studio Online (Build vNext, hosted pool)

我想在 VSO build vNext 上成功构建时自动标记提交。 我已经阅读了包含此页面 https://msdn.microsoft.com/Library/vs/alm/Build/scripts/variables 的文档,并且设置了一个小的 PowerShell 脚本。 首先,BUILD_REPOSITORY_AUTH_USERNAME 变量(及其好友密码)似乎是空的。我猜他们只适用于外部 gits ? 其次,构建的检查似乎是通过运行 LibGit2Sharp 的任务完成的,因此凭据未存储在任何帮助程序中。

这是我的 PowerShell 脚本:

git tag $Env:BUILD_BUILDNUMBER
git status
git config -l 
git push --progress https://$Env:GITUSER:$Env:GITPASSWORD@myrepo.visualstudio.com/DefaultCollection/_git/myproject tag $Env:BUILD_BUILDNUMBER
git status
exit

它在我的机器上运行良好,但在代理(托管池)上运行良好,但它似乎在推送命令时挂在代理上(1 小时后,它被控制器自动杀死)。

日志如下:

******************************************************************************
Starting task: Powershell: tools/GitCommands.ps1
******************************************************************************
HEAD detached at 819e778
nothing to commit, working directory clean
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
core.bare=false
core.filemode=false
core.symlinks=false
core.ignorecase=true
core.logallrefupdates=true
core.repositoryformatversion=0
remote.origin.url=https://myrepo.visualstudio.com/DefaultCollection/_git/myproject
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

******************************************************************************
Finishing task: PowerShell
******************************************************************************

如您所见,推送和状态命令都没有日志。 关于如何实现这一目标的任何想法?

回答问题(或更好的问题标题)。 让 vNext 构建来完成它。

如评论中所述,这不适用于外部 git 存储库。

我正在回答我自己想做的事情(git 标签是我想做的少数几个任务之一)。现在可以在脚本中执行 git 命令。文档在这里: https://www.visualstudio.com/en-us/docs/build/scripts/git-commands

这是方法:

启用脚本以执行 运行 Git 命令

授予构建服务版本控制权限:

  • 转到“版本控制”控制面板选项卡 ▼
  • 在“版本控制”选项卡上,select 要在其中执行 运行 Git 命令的存储库,然后是 select 项目集合构建服务。
  • 授予您想要 运行 的 Git 命令所需的权限。

通常您需要授予:

  • 分支创建:允许
  • 贡献:允许
  • 阅读:继承允许
  • 标签创建:继承允许

完成授予权限后,请务必点击“保存更改”。

启用您的构建定义 运行 Git.exe

在变量选项卡上设置此变量:system.prefergittrue

在选项选项卡上select允许脚本访问 OAuth 令牌。