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?
"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 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.
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.
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.
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."
See: Jira issue JENKINS-21809
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.
Open Git shell for project's workspace folder. Enable sparse-checkout:
git config core.sparsecheckout true
Update working tree:
git read-tree -mu HEAD
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/
Build the project again. This time only one sub-folder should appear in workspace folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With