下载 Azure DevOps Git Monorepo 下特定目录的源文件
Download Source files of a specific directory under 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 : fatal: InvalidOperationException encountered. At
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 encountered.: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 中没有这样的选项,其中文件发生变化,所有存储库都已下载到代理。
作为解决方法,您可以禁用下载存储库的选项并添加第一个任务来下载带有 sparse-checkout
的文件夹。
要禁用 repo 下载,请转到获取源并检查 "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
我有一个 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 : fatal: InvalidOperationException encountered. At 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 encountered.: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 中没有这样的选项,其中文件发生变化,所有存储库都已下载到代理。
作为解决方法,您可以禁用下载存储库的选项并添加第一个任务来下载带有 sparse-checkout
的文件夹。
要禁用 repo 下载,请转到获取源并检查 "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