5

I am trying to deploy to another server from Jenkins server, and I can't do it using Jenkins Build script.

When I am on the Jenkins server, I can deploy. For example:

:/var/lib/jenkins/workspace/MyProject$ scp my_file ubuntu@my_address:~/MyProject

Runs perfectly fine; however,

When I specify:

scp my_file ubuntu@my_address:~/MyProject

In "Execute Shell" under build in Jenkins window. I get the following error:

Host key verification failed.

I know that the first time I ran the above command directly on Jenkins server, I was prompted:

The authenticity of host 'my_address (my_address)' can't be established.
ECDSA key fingerprint is cf:4b:58:66:d6:d6:87:35:76:1c:aa:cf:9a:7c:78:cc.
Are you sure you want to continue connecting (yes/no)?

So I had to hit "yes" in order to continue. But since I already directly in the terminal, I don't have to do anything extra.

Second answer to this question: Jenkins Host key verification failed

indicates that, if I understand it correctly.

What am I missing? What can I do to fix my problem?

Community
  • 1
  • 1
Akavall
  • 76,296
  • 45
  • 192
  • 242

2 Answers2

14

I got it working, I needed to do two things:

1) I had to use -o StrictHostKeyChecking=no:

scp -v -o StrictHostKeyChecking=no my_file ubuntu@my_address:~/MyProject

instead of:

scp my_file ubuntu@my_address:~/MyProject

2) I needed to copy my id_rsa to /var/lib/jenkins/.ssh

The /var/lib/jenkins/.ssh folder and files inside of it need to be owned by jenkins.

Akavall
  • 76,296
  • 45
  • 192
  • 242
1

Old question but may be someone would find this useful:

ssh root@jenkinsMaster 'echo "$(ssh-keyscan -t rsa,dsa jenkinsSlave)" >> /root/.ssh/known_hosts'

Marco M
  • 1,185
  • 11
  • 12