繁体   English   中英

在Azure DevOps Git Monorepo下下载特定目录的源文件

[英]Download Source files of a specific directory under Azure DevOps Git Monorepo

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

私有代理是否可以下载受提交影响的源文件(在文件夹下)?

在此处输入图片说明

也就是说,当数据库文件夹得到提交时,代理仅下载数据库文件夹下的源文件。

这与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 :(未命中:(致命:InvalidO ... on。 。

我找到了解决方案。 首先,我更改为命令行任务(来自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

Azure DevOps中没有此类选项,其中所有回购都已下载到代理的文件中有更改。

解决方法是,您可以禁用下载存储库的选项,并添加第一个使用sparse-checkout下载文件夹的任务。

要禁用该存储库的下载,请转到“获取源”并选中“不同步源”:

在此处输入图片说明

使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM