Transformation of the Jenkins git project submodule

I want to update a submodule on a git clone.

Is there a way to do this with the Jenkins git command?

I am currently doing this ...

git branch: 'master', credentialsId: 'bitbucket', url: 'ssh://bitbucket.org/hello.git' 

However, it does not update the submodule after cloning

+7
git jenkins jenkins-pipeline
source share
3 answers

With the current Git plugin you don't even need to.

The GIT plugin supports repositories with submodules, which, in turn, are submodules themselves.
This should be included though:

in Task Configuration → Manage section source code, GIT → Advanced button (under branches for assembly) → Update submodules recursively

But the OP uses a pipeline.

So, a simple first step of assembly is enough:

 git submodule update --init --recursive 

However, the OP adds:

Yes, but if I use sh 'git submodule update --init --recursive' , will this use $HOME/id_rsa correctly? I want to pass my private key to this command, if possible.

Perhaps: in the Pipeline syntax you can define environment variables .
This means that you can set GIT_SSH_COMMAND ( using GIT 2.10+ ).
This allows you to reference your own private key .

 pipeline { agent any environment { GIT_SSH_COMMAND = 'ssh -i /path/to/my/private/key' } stages { stage('Build') { steps { sh 'printenv' sh 'git submodule update --init --recursive' } } } } 

If any clone includes an ssh URL, this ssh cache will use the right private key.

+9
source share

The git command as a pipeline stage is quite limited as it provides the default implementation of a more complex validation command . For a more complex configuration, you should use the checkout command, for which you can pass many parameters, including the desired configuration of the submodules.

What you want to use is probably something like this:

 checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: true, reference: '', trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[url: 'your-git-server/your-git-repository']]]) 

From the documentation it is often cumbersome to write such lines, I recommend that you use the Jenkins very well Snippet Generator (YourJenkins> yourProject> PipelineSyntax) to automatically generate a validation string!

+18
source share
 checkout([ $class: 'GitSCM', branches: scm.branches, doGenerateSubmoduleConfigurations: false, extensions: [[ $class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: '', trackingSubmodules: false ]], submoduleCfg: [], userRemoteConfigs: scm.userRemoteConfigs ]) 
+4
source share

All Articles