Issue
I want to update submodule on git clone.
Is there a way to do this with Jenkins pipeline Git command?
Currently I'm doing this...
git branch: 'master',
credentialsId: 'bitbucket',
url: 'ssh://bitbucket.org/hello.git'
It doesn't however update submodule once cloned
Solution
With the current Git plugin, you don't even need that.
The GIT plugin supports repositories with submodules which in turn have submodules themselves.
This must be turned on though:in Job Configuration -> Section Source Code Management, Git -> Advanced Button (under Branches to build) -> Recursively update submodules
But the OP is using pipeline.
So a simple first build step is enough:
git submodule update --init --recursive
However, the OP adds:
Yes but if I'm using
sh 'git submodule update --init --recursive'
, this will use$HOME/id_rsa
right? I want to pass in my private key for this command if possible.
It is possible: In the Pipeline syntax, you can define environment variables.
Which means you can set GIT_SSH_COMMAND
(with Git 2.10+).
That 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 involve an ssh url, that ssh clone will use the right private key.
Answered By - VonC