gpt4 book ai didi

git - 在 Visual Studio Team Services 中的构建作业中执行 git 命令(是 VSO)

转载 作者:IT王子 更新时间:2023-10-29 01:14:25 25 4
gpt4 key购买 nike

[环境:团队服务、GIT、托管构建代理]

我想创建一个能够执行以下操作的团队服务构建定义:

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

  2. 将生成的文件提交/推送回 repo

我可以毫无问题地完成#1。但我不确定我该怎么做 #2。

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

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

这是一个受支持的场景吗?有什么建议吗?

谢谢!


编辑

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

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

它似乎适用于 pull 等命令。但是当我尝试推送更改时,出现以下错误:

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

想法?

最佳答案

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

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

我想我应该把它分享出来,以帮助可能遇到与我相同情况的人。

这里我引用关键步骤(稍微修改了一下格式):

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.

使用这些设置,无需安装 Git 构建工具扩展或调整凭据管理器。您也不需要为 OAuth token 显式设置额外的 header 。我觉得这确实是一个非常巧妙的解决方案。 :)

但非常感谢 Eddie 和 VonC 的帮助!

关于git - 在 Visual Studio Team Services 中的构建作业中执行 git 命令(是 VSO),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38670306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com