git - VSTS 构建 : Git submodule automatization

标签 git azure-devops azure-pipelines

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

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

我们在第 49 行有一个错误。

我们认为实际上我们需要进行身份验证。但我们不确定。
我们使用: git pull 并且它有效
但是当我们这样做时:git submodule foreach git pull origin master。
我们收到“正在输入”的消息,但没有任何 react

有人已经有这个问题了吗?你是怎么解决的?

VSTS BUILD

最佳答案

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

确保您将构建定义设置启用为 允许脚本访问 OAuth token .如文档所述,这会将 token 填充到名为 System.AccessToken 的变量中。它还将 token 填充到 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 in $mods)
{
cd $mod
$cmd = 'git config http.' + $baserepo + $mod + '.extraheader "AUTHORIZATION: bearer ' + $env:System_AccessToken + '"'
write $cmd
iex $cmd
cd ..
}

然后运行 ​​cmd 或 powershell 步骤:
git submodule update --remote

最后,您应该在完成后清理 token ,这样 OAuth 就不会在您的构建代理上的 .git/config 文件中挂起:
$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 ..
}

关于git - VSTS 构建 : Git submodule automatization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45820526/

相关文章:

powershell - TFS 构建 powershell 脚本步骤 : Not able to access $(Date:yyyyMMdd) variable

azure - 错误: The requested resource requires user authentication: in AzureCLI task build pipeline

Git:每天获取提交的引用?

git - 在一行中添加并提交特定文件

configuration - Azure DevOps - Azure 资源组部署 : set value of subscription dynamically

git - Azure DevOps 单个 Repo 下的多个构建管道 使用 Git 时耗尽构建服务器内存

git - 在 git 中查看分阶段更改的差异

git - LabVIEW VI 的版本控制是如何工作的?

azure - 运行 Azure Pipeline 时 Chrome 版本不匹配

azure - 如何将 AzureKeyVault 中的 secret 用于 PowerShell -Credential?