VSTS Build : Git submodule automatization

2019-07-14 18:44发布

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 ?

VSTS BUILD

4条回答
倾城 Initia
2楼-- · 2019-07-14 19:23

Just found this Q/A with googling: You can use relative paths, ex:

origin  ssh://USERNAME@vs-ssh.visualstudio.com:22/PROJECT/_ssh/REPO (fetch)

the .gitmodules can contain:

[submodule "SUBMODULE"]
    path = SUBMODULE
    url = ../SUBMODULE

Source

Have a nice day :)

查看更多
一夜七次
3楼-- · 2019-07-14 19:25

It seems caused by the way VSTS build handle with git command with submodules.

I posted VSTS build hang up when execute git commands related to git submoudle, you can follow up the issue.

BTW, for the OAuth, you can add credential in .gitmodules.

查看更多
贼婆χ
4楼-- · 2019-07-14 19:26

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 ..
}
查看更多
地球回转人心会变
5楼-- · 2019-07-14 19:30

In your .gitmodules file you can try to add the organization name (case sensitive) in the url

[submodule "MySubModule"]
path = MySubModule
url = https://<Organization Name>@dev.azure.com/<Organization Name>/_git/<Project Name>
查看更多
登录 后发表回答