I have no problem doing this using git commands, as in Set Git submodule to shallow clone & sparse checkout? but I have a project using Jenkins and I'm using the checkout() function in the Groovy Pipeline syntax. I can't find any option to pass the --depth option to the git submodule update commands.
Asked
Active
Viewed 4,521 times
1 Answers
8
You should be able to use the extensions parameter in the checkout step:
checkout([
$class: 'GitSCM',
branches: [[name: 'master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]],
submoduleCfg: [],
userRemoteConfigs: [[url: 'git@yourrepo.com:repo/repo.git']]])
If you are using the snippet generator, select Additional Behaviors -> Advanced clone behaviors
to see the different options. Hope that helps!

Becca Gaspard
- 1,165
- 7
- 19
-
What does `depth: 0` do? Some resources, like [this one](https://github.com/magicmonty/bash-git-prompt/issues/241), suggest that depth 0 is invalid. – nh2 Aug 27 '18 at 23:38
-
This method is not working for me. It still clones the complete repository. – Abhishek Lodha Feb 12 '19 at 10:35
-
It may not work if the Pipeline plugin or Git plugin version is old enough. I don't remember the details and it will take too much time to recover it, but I am sure that long time ago I reproduced such a problem that depth option did not work. The solution for me was to update. If you use depth 0 the value 1 is used anyway (I can see that from the command which Git plugin starts). – Alexander Samoylov Nov 21 '19 at 13:56
-
I think `depth: 0` doesn't make much sense, but [this code](https://github.com/jenkinsci/git-plugin/blob/f563a47503e0072d7c41e2f44620be5ed50809df/src/main/java/hudson/plugins/git/extensions/impl/SubmoduleOption.java#L155) turns `depth: 0` into `depth: 1`. anyway. – nh2 Oct 27 '20 at 12:22