如何从Jenkins管道脚本中的远程仓库克隆目录?

Mar*_*son 4 git github jenkins jenkins-pipeline

我在GitHub Enterprise中有一个大型仓库,需要在我的Jenkins构建服务器上克隆一个子目录,然后构建该子目录.我正在使用管道脚本并立即拥有此功能:

node {
    stage ('checkout') {
        git url: 'git@github.devops.mycompany.local:Org/MyLargeRepo.git'
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要的是克隆 github.devops.mycompany.local:Org/MyLargeRepo/path/to/subproject

我知道我可能需要使用稀疏检出,但似乎无法解决如何在Jenkins管道脚本中配置它.有任何想法吗?

Von*_*onC 6

这看起来像声明性管道,而不是脚本化管道

使用后者,您可以使用此答案中看到的语法,基于The Jenkins Git插件中的hudson.plugins.git.extensions.impl.SparseCheckoutPaths:

checkout([$class: 'GitSCM', 
    branches: [[name: '*/branchName']],
    doGenerateSubmoduleConfigurations: false,
    extensions: [
        [$class: 'SparseCheckoutPaths',  sparseCheckoutPaths:[[$class:'SparseCheckoutPath', path:'folderName/']]]
                ],
    submoduleCfg: [],
    userRemoteConfigs: [[credentialsId: 'someID',
    url: 'git@link.git']]])
Run Code Online (Sandbox Code Playgroud)

不要忘记.git/info/sparse-checkout文件