Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

azure devops - VSTS Build : Git submodule automatization

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...