Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SparseCheckout in Jenkinsfile pipeline

In a jenkinsfile, I have specified the folderName through SparseCheckoutPaths which I want to checkout. But I am getting a whole branch checkout instead.

   checkout([$class: 'GitSCM', 
       branches: [[name: '*/branchName']],
       extensions: [[$class: 'SparseCheckoutPaths', path: 'FolderName']],
       userRemoteConfigs: [[credentialsId: 'someID',
       url: '[email protected]']]])
like image 543
HAr Avatar asked Apr 08 '17 11:04

HAr


People also ask

How do I pass Git credentials in Jenkins pipeline?

To understand how to configure credentials in a Jenkins environment: Using Credentials. gitToolName. Name of the git installation in the machine running the Jenkins instance (Check Global Tool Configuration section in Jenkins UI)

How do I add a Git repo to Jenkins pipeline?

To create your Pipeline project for a Git repository, click the Git button under Where do you store your code? In the Connect to a Git repository section, enter the URL for your Git repository in the Repository URL field. You now need to specify a local or a remote repository from which to build your Pipeline project.

What is pull scm in Jenkins?

In Jenkins, SCM stands for "Source Code Management". This option instructs Jenkins to obtain your Pipeline from Source Control Management (SCM), which will be your locally cloned Git repository.


2 Answers

Here comes the answer to my own question. For a bit of background how does it work, there is flag/configuration for git client called sparsecheckout which is responsible for this kind of checkout. Additionally, a sparse-checkout named file is also required. For more info look here.

My problem was the syntax for the Jenkinsfile and correct one is as follows:

checkout([$class: 'GitSCM', 
    branches: [[name: '*/branchName']],
    doGenerateSubmoduleConfigurations: false,
    extensions: [
        [$class: 'SparseCheckoutPaths',  sparseCheckoutPaths:[[$class:'SparseCheckoutPath', path:'folderName/']]]
                ],
    submoduleCfg: [],
    userRemoteConfigs: [[credentialsId: 'someID',
    url: '[email protected]']]])

for more info, here comes the github-link

like image 123
HAr Avatar answered Sep 23 '22 21:09

HAr


Your syntax looks good, but, as seen in "jenkinsci/plugins/gitclient/CliGitAPIImpl.java", did you specify the right configuration?

private void sparseCheckout(@NonNull List<String> paths) throws GitException, InterruptedException {

    boolean coreSparseCheckoutConfigEnable;
    try {
        coreSparseCheckoutConfigEnable = launchCommand("config", "core.sparsecheckout").contains("true");
    } catch (GitException ge) {
        coreSparseCheckoutConfigEnable = false;
    }

In other words, is git config core.sparsecheckout equal to true in the repo you are about to checkout?

like image 28
VonC Avatar answered Sep 22 '22 21:09

VonC