SparseCheckout in Jenkinsfile pipeline

佐手、 提交于 2019-11-27 16:43:24

问题


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: 'git@link.git']]])

回答1:


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: 'git@link.git']]])

for more info, here comes the github-link




回答2:


Your syntax looks good, but, as seen in "jenkinsci/plugins/gitclient/CliGitAPIImpl.java", dod 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 equals to true in the repo you are about to checkout?



来源:https://stackoverflow.com/questions/43293334/sparsecheckout-in-jenkinsfile-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!