Sparse Checkout using Jenkins

I was recently working on a project where I required only a particular folder inside a bitbucket repository to be cloned and tracked on the server. This was when I stumbled upon the sparse checkout feature that Jenkins offered. I decided to write this short post so that it might help you in case you have a similar requirement as me.

I have the following folder structure:

Here,I would like to clone and track only the survey folder highlighted above.
Here is how you can go about doing this,
1) Start off by creating a new freestyle project
2) Under the configure page, navigate to source code management section.
3) Here, click on the git option. Enter the repository URL followed by the credentials and the branch that you would like to build.
4) Now, besides the additional behaviour tab click on the Add dropdown menu, and select Sparse Checkout path option.
5) A textbox will be displayed. Here, enter the path to the folder that you would like to clone.

Go ahead and save your configuration
6) Click on Build Now.
Only the folder which was specified would be cloned and tracked on the server.

And that’s it, you successfully did a sparse checkout using Jenkins!
Feel free to ask any further queries you have.

2 thoughts on “Sparse Checkout using Jenkins

    1. Hi, thanks for your comment. If you’d like to exclude a certain directory from within the sparse checkout directory, you can ssh into the Jenkins server(where your repository is getting cloned). Navigate to the cloned repo, then `vi .git/info/sparse-checkout` . Here in this file, you can add the directory that you would like to exclude.
      Eg:
      survey/*
      !survey/survey_db/*
      Now in the above example, all the files and subdirectories under the “survey” folder will be cloned except the “survey_db” folder
      Or if that doesn’t work, you could try adding the directory to exclude in .git/info/exclude
      If that doesn’t help either you could use the following command to not keep track of the folder in future checkouts,
      git update-index –assume-unchanged folder_name/*

Leave a Reply

Your email address will not be published.