I'm trying to do something similar to what was done in here but I'm running Jenkins on a Windows server and am trying to pass in credentials from Jenkins' credentials store, it warrants a different post.
In the comments for the post above, I've looked at this post and now have this in my pipeline:
withCredentials([sshUserPrivateKey(credentialsId:'ci', keyFileVariable:'GITHUB_KEY')]){
withEnv(["GIT_SSH_COMMAND=ssh -i $GIHUB_KEY -o StrictHostKeyChecking=no]){
bat script: 'git submodule update --init --recursive'
}
}
However, when the build runs, it get an error due to login failure:
using GIT_SSH to set credentials <credentials_description>
> C:\<git_install_path>\git.exe submodule update --init --recursive <submodule_name> # timeout=10
...
...
hudson.plugins.git.GitException: Command "C:\<git_install_path>\git.exe submodule update --init --recursive <submodule_name>" returned status code 1:
stdout:
stderr: Cloning into '<Jenkins job folder>'
Logon failed, use ctrl+c to cancel basic credential prompt
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for '<git url>': No such file or directory
fatal: clone of '<submodule url>' into submodule path '<local submodule path>' failed
Failed to clone '<submodule>'. Retry scheduled
...
Is there a way to pass in these credentials from Jenkins when calling the git submodule
command? Or do I need to set the GIT_SSH_COMMAND
in the environment block like in the first linked post and have the private key stored on the build box somewhere?
EDIT: I've also tried using the checkout syntax but I get the same login failure error
checkout([
$class: 'GitSCM',
branches: [[name '*/<branch_name'>]],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false
]],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId:'ci', url:'<git_url>']]
])