Reputation: 131
I am trying this pipeline script
stage('Deploy') {
steps {
container('docker') {
sshagent (credentials: ['sshsupersecret_key']){
sh 'git clone [email protected]:org_name/appconfigs.git'
}
When trying to clone the git repo , I am getting Host key verification failed.
. I am using the right key as it's the same key which jenkins is using to clone the application code in the same pipeline . Access key has been already added to the repo of bitbucket .
If I try this workaround it's working ,
steps {
container('docker') {
script {
withCredentials([sshUserPrivateKey(credentialsId: "sshsupersecret_key", keyFileVariable: 'keyfile')]) {
sh """
mkdir ~/.ssh
chmod 700 ~/.ssh
cp ${keyfile} ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
cp ${keyfile} ~/.ssh/id_rsa
ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts
git clone [email protected]:org_name/appconfigs.git
"""
}
}
If I am already providing the credentials in first method , why it's not able to authenticate ? I am running Jenkins on Kubernetes.
Upvotes: 0
Views: 1929
Reputation: 9222
Maybe try adding this
echo "Host *" > ~/.ssh/config
echo " StrictHostKeyChecking no" >> ~/.ssh/config
Upvotes: 1