在Visual Studio Team Services中执行构建作业中的git命令(是VSO) [英] Executing git commands inside a build job in Visual Studio Team Services (was VSO)

查看:163
本文介绍了在Visual Studio Team Services中执行构建作业中的git命令(是VSO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[Environment:Team Services,GIT,托管构建代理]



我想创建一个Team Services构建定义,它可以执行以下操作: / p>


  1. 执行脚本以根据回购库中的现有文件生成一些新文件

  2. 提交/推送那些生成的文件回购


问题。但我不确定我能做到#2。



我发现我实际上能够在构建作业中运行git.exe。但我不确定我如何将凭据传递给git。基于构建日志,它失败了,因为它试图从stdin获取用户名。



我尝试在构建定义中添加一个步骤,比如git config - 全球user.name xxxx,但它仍然没有帮助。

这是一个受支持的方案吗?任何建议?



谢谢!




编辑



我在构建脚本中尝试了以下方法:

  git -c http.extraheader =AUTHORIZATION:bearer%SYSTEM_ACCESSTOKEN%pull ... 

它似乎适用于拉等命令,但当我试图推动更改时,我得到了下面的错误:

 致命:无法访问'https://example.visualstudio.com/SampleTeam/_git/SampleRepo/':SSL读取:错误:00000000:lib(0):func(0):reason(0),errno 10054 

想法?

解决方案

很抱歉,在这里回答我自己的问题...



我刚从一些TFS专家那里得到了一些提示,他指出我这篇文章: https://www.visualstudio.com/en-us/docs/build / scripts / git-commands ,whi我完全解决了我的问题。



我认为我应该分享它,以帮助任何可能遇到与我一样的情况。



这里我引用了关键步骤(重新格式化了一下):

lockquote

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



转至版本控制控制台选项卡




  • 团队服务: https:// {your-account} .visualstudio.com / DefaultCollection / {your-team-project} / _admin / _versioncontrol

  • :// {your-server}:8080 / tfs / DefaultCollection / {your-team-project} / _admin / _versioncontrol


    版本控制标签上,选择要运行Git命令的存储库,然后选择 Project Collection构建服务(帐户名称)。授予您希望运行的Git命令所需的权限。通常情况下,您需要授予:


    • 创建分支:允许

    • 贡献:允许

    • 阅读:继承允许 :继承允许



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

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




    • 变量标签设置此变量: system.prefergit = true

    • 选项选项卡
    • 通过这些设置,不需要安装Git Build Tools扩展或调整Credential Manager。您无需为OAuth令牌显式设置额外的标头。我觉得这确实是一个非常好的解决方案。 :)



      但是真的很感谢Eddie和VonC的帮助!


      [Environment: Team Services, GIT, hosted build agent]

      I'd like to create a Team Services build definition that is able to do the following:

      1. Executing a script to generate some new files based on existing files in the repo

      2. Commit/push those generated files back to repo

      I can do #1 with no problem. But I'm not sure how I can do #2.

      I discovered I was actually able to run git.exe from inside a build job. But I'm not sure how I can pass the credential to git. Based on the build logs, it's failing because it's trying to get the username from stdin.

      I tried adding a step in the build definition with something like "git config --global user.name xxxx" but it still didn't help.

      Is this a supported scenario at all? Any suggestions?

      Thanks!


      Edit

      I tried the following approach in my build script:

      git -c http.extraheader="AUTHORIZATION: bearer %SYSTEM_ACCESSTOKEN%" pull ...
      

      It seemed to work for commands like pull, etc. But when I was trying to push the changes, I got the below error:

      fatal: unable to access 'https://example.visualstudio.com/SampleTeam/_git/SampleRepo/': SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054
      

      Thoughts?

      解决方案

      Sorry to answer my own question here...

      I just got some hint from some TFS expert, who pointed me to this article: https://www.visualstudio.com/en-us/docs/build/scripts/git-commands, which perfectly solved my problem.

      I think I should share it out to help whoever might run into the same situation as I did.

      Here I am quoting the key steps (reformatted a bit):

      Grant version control permissions to the build service

      Go to the Version Control control panel tab

      • Team Services: https://{your-account}.visualstudio.com/DefaultCollection/{your-team-project}/_admin/_versioncontrol

      • On-premises: https://{your-server}:8080/tfs/DefaultCollection/{your-team-project}/_admin/_versioncontrol

      On the Version Control tab, select the repository in which you want to run Git commands, and then select Project Collection Build Service (account_name). Grant permissions needed for the Git commands you want to run. Typically you'll want to grant:

      • Branch creation: Allow
      • Contribute: Allow
      • Read: Inherited allow
      • Tag creation: Inherited allow

      When you're done granting the permissions, make sure to click Save changes.

      Enable your build definition to run Git.exe

      • On the variables tab set this variable: system.prefergit = true
      • On the options tab select Allow scripts to access OAuth token.

      With these settings, there is no need to install the Git Build Tools extension or tweak the Credential Manager. You don't need to explicitly set the extra header for OAuth token, either. I feel it's indeed a very neat solution. :)

      But really appreciate the help from Eddie and VonC!

      这篇关于在Visual Studio Team Services中执行构建作业中的git命令(是VSO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆