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
  • 82,592
  • 51
  • 207
  • 251

3 Answers3

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
  • 82,592
  • 51
  • 207
  • 251
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,215
  • 12
  • 12
0

Make sure that you're first settingup ssh connection to remote host then try to copy the things to remote host.

ssh -o StrictHostKeyChecking=no user@ip_addr

scp file_name user@ip_addr:/home/user

Shree
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 26 '22 at 06:23