in the following steps i will show you how to checkout a directory from git by using jenkins.
Here iam having a repository called decodingdevops in git.
this repository has one directory called devops and some other files.
Now I will checkout only this devops directory from git by using jenkins.
go to jenkins
When you are configuring job you can see source code management section.
Select git and enter your git clone url and enter your branch and give your git repository credentials.
checkout a directory from git by using jenkins
and in the below section you can see additional Behaviors in source code management section click on the add.
and scroll down you can see sparse checkout paths click on sparse checkout paths.
now one new small window is added.
You can see path option here enter your path of a directory.
Here i entered devops.
and save it.
Now build the job you can see in the workspace I got only devops directory.
We will not get any other remaining files from git repository to jenkins workspace.
checkout a subdirectory from git by using jenkins
let us assume that in the git repository i have directory called devops, in that i have xyz1 sub directory and in that i have xyz2 subdirectory.
So now i want to checkout this xyz2 subdirectory.
Enter devops/xyz1/xyz2 in sparse checkout paths. save the job and build job,
So this will checkout only subdirectory xyz2.
If you want to checkout a perticular subdirectory, you have to enter path up to that that subdirectory.