On Wednesday, February 5, 2025 at 8:46:31 AM UTC-7 Xavier Raynaud wrote:

Hi all,

In my Jenkinsfile, I use the checkout 
<https://www.jenkins.io/doc/pipeline/steps/workflow-scm-step/> step to 
perform a git checkout.
My git repo has some submodules; which have also, themselves, submodules.

As of today, I use the following checkout extentions:
*[$class: 'CleanBeforeCheckout', deleteUntrackedNestedRepositories: true ]*
*[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: 
false, recursiveSubmodules: true, reference: '', threads: 4, timeout: 30, 
trackingSubmodules: false, shallow: shallow_clone, depth: 1],*

The former extension runs "git clean -ffxd" before performing git checkout.
But, as far as i know, this option is not propagated to submodules: in 
submodules, only "git -fxd" is performed.
Therefore, some "phantom" gits repos can be left in submodules.

Is there a way to run "git clean -ffxd" in submodules ?


Could you perform the cleanup yourself in the Pipeline immediately before 
the checkout?  Something like "sh '[ -d .git ] && git submodule foreach 
--recursive git clean -xffd'"
 

Is it a known issue ?


https://stackoverflow.com/questions/51963783/what-is-the-workflow-to-clean-git-submodules-on-clones
 
highlights some of the problems attempting to clean submodules on an 
existing clone

https://issues.jenkins.io/browse/JENKINS-60727 asks to clean the submodules 
of submodules
https://issues.jenkins.io/browse/JENKINS-55875 describes a failure case 
with submodules
https://issues.jenkins.io/browse/JENKINS-27625 describes another case
https://issues.jenkins.io/browse/JENKINS-14083 describes another case

More examples of those are available.  The complexities of handling 
submodules was one of the reasons why a Google Summer of Code project added 
git plugin support to the withCredentials Pipeline step.  When all else 
fails, you can take complete control of the checkout and perform the exact 
git commands that you need for your submodule configuration.

Mark Waite

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/jenkinsci-users/87543d4f-af5e-4d60-b3a3-6a60e8dc2a3an%40googlegroups.com.

Reply via email to