首页 > 解决方案 > 下载 Azure DevOps Git Monorepo 下特定目录的源文件

问题描述

我有一个 Git monorepo,其中有两个文件夹(两个单独的解决方案)。我为每个解决方案设置了两个 CI 构建。每个 CI 都已Enable Continuous Integration激活。对于每个 CI 管道,我Path filters为每个文件夹指定(排除),以防止 CI 构建为其他文件夹的任何提交。

私人代理有没有办法下载受提交影响的源文件[文件夹下]?

在此处输入图像描述

也就是说,当Database文件夹获得提交时,代理只下载Database文件夹下的源文件。

这有关系Checkout submodules吗?

更新

这是我的 PowerShell 脚本:

cd $(Build.SourcesDirectory)

git config --global user.email "my_email_here"
git config --global user.name "my_username_here"

git init
git remote add origin -f https://my_username_here@dev.azure.com/my_username_here/TxProject/_git/testtwoprojects
git config core.sparseCheckout true
Set-Content -Path .git/info/sparse-checkout -Value "Source/*"
git pull origin master

我收到的错误是:

git:致命:遇到 InvalidOperationException。在 C:\agent_work_temp\b5feb3b7-f104-48a0-94d8-a8c769e84a6e.ps1:8 char:1 + git remote add origin -f https://my_username_here@dev.azure.com/my_username_here/TxProjec ... + ~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (fatal: InvalidO...on meet.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError PowerShell exited with code '1' .

解决方案

我找到了解决方案。首先,我更改为命令行任务(来自 PowerShell)并2>&1在命令末尾添加。

最终代码是:

cd $(Build.SourcesDirectory)

git config --global user.email "user_email"
git config --global user.name "user_name"

git init
git remote add origin -f LINK_TO_REPO 2>&1
git config core.sparseCheckout true
echo Source/ >> .git/info/sparse-checkout
git pull origin master 2>&1

标签: gitazure-devopsazure-pipelinesazure-repos

解决方案


Azure DevOps 中没有这样的选项,其中一个文件发生了变化,所有的 repo 都被下载到了代理。

作为一种解决方法,您可以禁用下载存储库的选项并添加第一个使用sparse-checkout.

要禁用 repo 的下载,请转到 Get Sources 并选中“Don't sync sources”:

在此处输入图像描述

sparse-checkout仅用于下载一个文件夹的 PowerShell 脚本:

cd $(Build.SourcesDirectory)
git init
git config core.sparseCheckout true 
git remote add origin -f $(Build.Repository.Uri)
$commit = "$(Build.SourceVersion)"
# Get the folder name from the git commit info - maybe will not work always, need to improve it
$folder = (((git show $commit)[6] -split 'a/')[1] -split '/')[0]
Set-Content -Path .git/info/sparse-checkout -Value "$folder/*"
git checkout master

推荐阅读