【问题标题】:Git tag at the end of build on Visual Studio Online (Build vNext, hosted pool)在 Visual Studio Online 上构建结束时的 Git 标记(构建 vNext,托管池)
【发布时间】:2015-08-30 02:57:42
【问题描述】:

我想在 VSO 构建 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
******************************************************************************

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

【问题讨论】:

  • 似乎没有环境变量 BUILD_REPOSITORY_AUTH_USERNAME 了。所以如何授权进入git是一个大问题。

标签: git powershell continuous-integration azure-devops alm


【解决方案1】:

回答问题(或更好的问题标题)。 只需让 vNext 构建完成即可。

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

【讨论】:

  • 知道如何在其中获得自定义的脚本定义变量,例如 GitVersion 的输出?
  • 想通了 - 您可以使用日志命令更新 buildNumber,然后使用上面的策略! github.com/Microsoft/vso-agent-tasks/issues/375
  • 仅供参考,使用“外部 Git”存储库时,“标签源”选项不可用。
  • 这里重要的警告:您不能使用在 .. 构建的“构建”部分期间修改的 ANY 变量。 “完成构建”步骤不在构建代理上运行,因此将不起作用。 BuildNumber 是一个特例。见:stackoverflow.com/a/41028346/237723
  • 如果您想使用在构建过程中创建的构建变量,则无法使用它,因为并非所有人都希望用一些无意义的构建号标记我们的源代码。
【解决方案2】:

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

这里是操作方法:

启用脚本以运行 Git 命令

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

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

通常你会想要授予:

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

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

启用构建定义以运行 Git.exe

在变量选项卡上设置此变量:system.prefergit 到 true

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

【讨论】:

  • 在git push origin *ref* 我得到fatal: could not read Username for *URL*: Invalid argument,知道我能做什么吗?我是否需要将凭据添加到 TFS 服务器(本地)?
猜你喜欢
  • 1970-01-01
  • 2014-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-27
  • 1970-01-01
  • 2014-11-14
相关资源
最近更新 更多