git - 下载 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
解决方案
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
推荐阅读
- javascript - 如何在 react js 的这个 get 过滤器中设置 .val()?
- kubernetes - 尝试从 pod 访问 Kubernetes API 时出现 403 禁止错误
- python - 注册表单窗口未正确显示
- visual-studio-code - 如何使用 Visual Studio Code 打开巨大的 csv 文件?
- upgrade - 要求地址(this).transfer(msg.value) 抛出错误
- android - Android FlexboxLayoutManager 重新创建项目
- ruby-on-rails - Active Record in_batches 与 find_in_batches
- r - 在 R 中的数据框中的某些位置添加多列
- c - 在 C 中,我可以推迟头文件的“typedef”,直到我包含并使用头文件?
- rust - 功能 'xxx' 依赖于 'yyy',这不是可选依赖项