Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to accept ssh host verification in jenkins ssh agent

Refer to following jenkins pipeline script

sshagent(['sshuser']) {
    sh "git clone ssh://[email protected]/test/test-commit.git"         
}

I am always getting following logs in jenkins

Cloning into 'test-commit'...
Host key verification failed.
fatal: Could not read from remote repository.

Tried a few tricks to auto accept the host verification but all failed, very frustrated.

like image 457
王子1986 Avatar asked Oct 19 '25 07:10

王子1986


1 Answers

If your main concern is with git you could use the GIT_SSH_COMMAND environment variable. It allows you to inject ssh options:

stage('My git stage') {
    environment {
        GIT_SSH_COMMAND = "ssh -o StrictHostKeyChecking=no"
    }
    steps {
        sshagent(['sshuser']) {
            sh "git clone ssh://[email protected]/test/test-commit.git"         
        }
    }
}

Mind you, this comes with some security concerns. You might want to investigate: https://www.symantec.com/connect/articles/ssh-host-key-protection

like image 90
ChappIO Avatar answered Oct 21 '25 01:10

ChappIO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!