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

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

问题描述

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

我们遵循本指南:

解决方案

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

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

这是我使用的 Powershell 脚本:

$mods = (git submodule status) |% { ($_.Trim() -split " ")[1] }$baserepo = ($env:BUILD_REPOSITORY_URI).TrimEnd($env:BUILD_REPOSITORY_NAME)foreach($mod 中的 $mods){光盘 $mod$cmd = 'git config http.'+ $baserepo + $mod + '.extraheader "AUTHORIZATION: Bearer ' + $env:System_AccessToken + '"'写 $cmdiex $cmd光盘..}

然后运行 ​​cmd 或 powershell 步骤:

git submodule update --remote

最后,您应该在完成后清理令牌,这样 OAuth 就不会挂在构建代理的 .git/config 文件中:

$mods = (git submodule status) |% { ($_.Trim() -split " ")[1] }$baserepo = ($env:BUILD_REPOSITORY_URI).TrimEnd($env:BUILD_REPOSITORY_NAME)foreach($mod 中的 $mods){光盘 $mod$cmd = 'git config --unset-all http.'+ $baserepo + $mod + '.extraheader'写 $cmdiex $cmd光盘..}

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

We followed this guide : https://www.visualstudio.com/en-us/docs/build/scripts/git-commands#enable

We have an error at line 49.

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 ?

解决方案

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

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.

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 ..
}

Then run a cmd or powershell step:

git submodule update --remote

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天全站免登陆