0
votes

I have a Git monorepo which has two folders (two separate solutions) in it. I have set two CI builds for each solution. Each CI has the Enable Continuous Integration activated. For each CI pipeline, I have specified Path filters (Exclude) for each folder so as to prevent CI builds for any commit for the other folder.

Is there a way for the private agent to download ONLY the source files [under a folder] which got affected by a commit?

enter image description here

That is, when the Database folder gets a commit, the agent downloads only the source files under the Database folder.

Is this related to Checkout submodules?

UPDATE

This is my PowerShell script:

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://[email protected]/my_username_here/TxProject/_git/testtwoprojects
git config core.sparseCheckout true
Set-Content -Path .git/info/sparse-checkout -Value "Source/*"
git pull origin master

The error I receive is:

git : fatal: InvalidOperationException encountered. At C:\agent_work_temp\b5feb3b7-f104-48a0-94d8-a8c769e84a6e.ps1:8 char:1 + git remote add origin -f https://[email protected]/my_username_here/TxProjec ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (fatal: InvalidO...on encountered.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError PowerShell exited with code '1'.

SOLUTION

I found a solution. First I changed to a Command Line task (from PowerShell) and added 2>&1 at the end of the commands.

Final code is:

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
1

1 Answers

1
votes

There is no such option in Azure DevOps, where there is a change in a file all the repo is been downloaded to the agent.

As a workaround, you can disable the option to download the repository and add the first task that downloads the folder with sparse-checkout.

To disable the downloading of the repo go to Get Sources and check "Don't sync sources":

enter image description here

A PowerShell script that uses sparse-checkout to download only one folder:

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