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]']]])
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)
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.
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.
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
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With