Jenkins and Git sparse checkouts

GitJenkinsSparse Checkout

Git Problem Overview


I have a large repository in Git. How do I create a job in Jenkins that checks out just one sub-folder from the project?

Git Solutions


Solution 1 - Git

Jenkins Git Plugin support sparse checkouts since git-plugin 2.1.0 (April, 2014). You will need git >= 1.7.0 for this feature. It is under "Additional Behaviors" -> "Sparse Checkout paths."

screenshot

See: Jira issue JENKINS-21809

Solution 2 - Git

You can use sparse checkout feature of Git. Note that Git still clones whole repository to local disk. That's not too bad however, because it is compressed.

  1. Create a new job in Jenkins, set Git repository in Source Code Management section.

  2. Build the project. This will clone whole repository to local disk.

  3. Open projects's workspace folder, delete everything there except .git folder.

  4. Open Git shell for project's workspace folder. Enable sparse-checkout:

    git config core.sparsecheckout true
    
  5. Update working tree:

    git read-tree -mu HEAD
    
  6. Create sparse-checkout file in .git/info folder. Add path to sub-folder you want to checkout to that file, like so (note trailing slash):

    folder/to/include/
    
  7. Build the project again. This time only one sub-folder should appear in workspace folder.

Solution 3 - Git

You could have a custom step that would just use

git checkout your-branch -- the/desired/path anthother/desired/path

To clear it you could just rm -rf the working folder and recreate it with mkdir workingdir. This would require you to specify this option on the git level of the above command:

git --working-dir="/path/to/workingdir" checkout your-branch -- the/desired/path anthother/desired/path

All this depends on how well you know Jenkins.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPavel ChuchuvaView Question on Stackoverflow
Solution 1 - Gituı6ʎɹnɯ ꞁəıuɐpView Answer on Stackoverflow
Solution 2 - GitPavel ChuchuvaView Answer on Stackoverflow
Solution 3 - GitAdam DymitrukView Answer on Stackoverflow