Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins and Git sparse checkouts

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?

like image 967
Pavel Chuchuva Avatar asked May 28 '12 23:05

Pavel Chuchuva


People also ask

What is Git sparse checkout?

"Sparse checkout" allows populating the working directory sparsely. It uses the skip-worktree bit (see git-update-index[1]) to tell Git whether a file in the working directory is worth looking at. If the skip-worktree bit is set, and the file is not present in the working tree, then its absence is ignored.

How Jenkins works with Git?

How does Jenkins integrate with Git? Go to Jenkins dashboard, click on “Manage Jenkins.” Now follow these steps- Manage Plugins -> 'Available' tab -> Enter Git in search bar and filter -> Install required plugin. After the installation, all you need to do is click on “Configure System” and go to the 'GitHub' section.

Can we connect Git with Jenkins?

With the help of the Git plugin Jenkins can easily pull source code from any Git repository that the Jenkins build node can access. The GitHub plugin extends upon that integration further by providing improved bi-directional integration with GitHub.

How does Jenkins pull from Git?

The Jenkins git plug-in The key to Jenkins Git integration is the Git plug-in. One can easily install the Jenkins Git plug-in through the Jenkins administrative console, and once properly configured, it gives all Jenkins build jobs the option to pull content from a Git-compatible source code repository.


2 Answers

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

like image 190
uı6ʎɹnɯ ꞁəıuɐp Avatar answered Sep 18 '22 14:09

uı6ʎɹnɯ ꞁəıuɐp


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.

like image 40
Pavel Chuchuva Avatar answered Sep 19 '22 14:09

Pavel Chuchuva