checkout a directory from git by using jenkins

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.

checkout a directory from git by using jenkins

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

create job

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.

checkout a directory from git by using jenkins

and scroll down you can see sparse checkout paths click on sparse checkout paths.

checkout a directory from git by using jenkins

now one new small window is added.

checkout a directory from git by using jenkins

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.

checkout a directory from git by using jenkins

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.

devops/xyz1/xyz2

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.

 

2 Responses

  1. shan says:

    HI,
    IF i want to oly files rather than directory.
    how can we achieve it .
    let say devops dir inside it i have 2 files so whiles cloning i shld get that 2 files not devops directory.Is that possible?

  2. ASHKA SHAH says:

    Incase of i have two subdirs,
    devops/xyz1/xyz2
    abc/devops

    and i mention sparse checkout path as devops
    it checkout both these directories

    I want to limit it to checkout devops/xyz1/xyz2

    What can I do?

Leave a Reply

Your email address will not be published. Required fields are marked *