如何在jenkins groovy中检出SCM的子目录? [英] How to checkout a subdirectory of an SCM in jenkins groovy?
问题描述
我有一个git hub存储库ABC.git,它具有以下目录src,config,env,test.我只想将src和config文件夹签出到我的Jenkins工作区中.
I have a git hub repository ABC.git it has the following directories src ,config,env, test. I just want to checkout the src and config folder into my Jenkins workspace.
我可以使用SCM插件将完整的存储库签出到我的jenkins工作区中.
I am able to checkout the complete repository into my jenkins workspace using the SCM plugin.
用于检出完整分支的命令:
command used for checking out complete branch :
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanCheckout']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: '<gitCredentials>', url: '<gitRepoURL>']]
])
推荐答案
使用它来签出特定的目录/子目录:扩展名:[[$ class:'SparseCheckoutPaths',sparseCheckoutPaths:[[path:'/directory/路径/此处']]]]
Use this to checkout specific directory/subdirectory: extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: '/directory/path/here']]]]
因此您的脚本将如下所示:结帐([ $ class:'GitSCM',
分支机构:[[名称:'*/master']],
doGenerateSubmoduleConfigurations:false,
扩展名:[[$$ class:'CleanCheckout'],
[$ class:'SparseCheckoutPaths',
sparseCheckoutPaths:[[路径:'/directory/path/here']]]] >
submoduleCfg:[],
userRemoteConfigs:[[credentialsId:'< gitCredentials>',url:'< gitRepoURL>']]
])
So your script will look like this:
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanCheckout'],
[$class: 'SparseCheckoutPaths',
sparseCheckoutPaths: [[path: '/directory/path/here']]]],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: '<gitCredentials>', url: '<gitRepoURL>']]
])
这篇关于如何在jenkins groovy中检出SCM的子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!