Search code examples
jenkinsgroovyjenkins-pipeline

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]']]])

Solution

  • 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