VSTS Build:Git子模块自动化 [英] VSTS Build : Git submodule automatization

查看:56
本文介绍了VSTS Build:Git子模块自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们从TFS切换到GIT. 每当我们启动新版本时,我们都在尝试更新子模块.

We switched from TFS to GIT. We are trying to update the submodule everytime we launch a new build.

我们遵循了本指南: https://www.visualstudio.com/zh-CN/docs/build/scripts/git-commands#enable

第49行出现错误.

我们认为实际上我们需要进行身份验证.但是我们不能确定. 我们使用了:git pull并且有效 但是当我们这样做时:git子模块foreach git pull origin master. 我们收到消息正在进入",什么也没发生

We think that actually we need to authenticate. But we arent sure. We used : git pull and it works but when we do this : git submodule foreach git pull origin master. We have the message "Entering" and nothing happens

有人已经有这个问题了吗?您是如何解决的?

Did somebody already have this problem ? How did you solve it ?

推荐答案

这是身份验证问题.您需要将OAuth令牌放入每个子模块存储库中.

It is an authentication issue. You need to get the OAuth token into each of the submodule repos.

确保已启用构建定义设置,以允许脚本访问OAuth令牌.如记录所示,这会将令牌填充到名为System.AccessToken的变量中.还将令牌填充到git config设置中,启用设置后在运行它时,您将在获取源步骤的末尾看到它.这就是git对VSTS进行身份验证的方式.您需要为每个存储库构建一个config语句,并且需要cd到该子模块中才能在该存储库中发布它.

Make sure you have the build definition setting enabled to Allow scripts access to the OAuth token. As documented, this stuffs the token into a variable called System.AccessToken. It also stuffs the token into a git config setting that you'll see at the end of your get sources step when you run it after enabling the setting. This is how git authenticates to VSTS. You'll need to build a config statement for each of the repos, and you'll need to cd into that submodule to issue it in that repo.

这是我使用的Powershell脚本:

Here is the Powershell script I used:

$mods = (git submodule status) | % { ($_.Trim() -split " ")[1] }
$baserepo = ($env:BUILD_REPOSITORY_URI).TrimEnd($env:BUILD_REPOSITORY_NAME)
foreach($mod in $mods)
{
cd $mod
$cmd = 'git config http.' + $baserepo + $mod + '.extraheader "AUTHORIZATION: bearer ' + $env:System_AccessToken + '"'
write $cmd
iex $cmd
cd ..
}

然后运行cmd或powershell步骤:

Then run a cmd or powershell step:

git submodule update --remote

最后,您应该在使用完令牌后清理令牌,以使OAuth不会在构建代理的.git/config文件中闲逛:

Lastly, you should clean up the token after you are done with it, so the OAuth doesn't hang out in your .git/config file on your build agent:

$mods = (git submodule status) | % { ($_.Trim() -split " ")[1] }
$baserepo = ($env:BUILD_REPOSITORY_URI).TrimEnd($env:BUILD_REPOSITORY_NAME)
foreach($mod in $mods)
{
cd $mod
$cmd = 'git config --unset-all http.'+ $baserepo + $mod + '.extraheader'
write $cmd
iex $cmd
cd ..
}

这篇关于VSTS Build:Git子模块自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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