6

I'm trying to deploy my code to a remote server. So far I've tried

  • Publish over SSH Plugin: the problem is that I'm unable to keep file permissions
  • Rsync command: this keeps the file permissions, but the problem is that I don't know how to set the password for it to work automatically

This is what I get:

[JenkinsBuild] $ /bin/sh -xe /var/lib/jenkins/tmp/hudson4646064064846581974.sh
+ rsync -PSauve ssh --exclude=JenkinsBuild app bower.json config gruntfile.js karma.conf.js LICENSE.md Makefile node_modules package.json Procfile protractor.conf.js public README README.md server.js john@192.168.2.10:/srv/dp/prod
Host key verification failed.
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]

Any ideas what I'm doing wrong here?

| improve this question | | | | |
4
Host key verification failed.

The account running jenkins likely has a bad value for the host key for the machine you are sshing to in ~/.ssh/known_hosts.

| improve this answer | | | | |
  • thanks this gave me a hint on what was wrong, and since I don't have enough points I can't give you a +1 – JAT2007 Sep 10 '14 at 20:08
3

Well I replaced the know_host files but I was still having issues. so for anyone that has issues with the know_host file you would fix the offending key by doing a:

ssh-keygen -R hostnameOfOfendingKey

and this will remove the ofending key and now your known_host file is working again.

NOW to resolve the other issue I found the answer in this other place: https://stackoverflow.com/questions/25755418/executing-rsync-in-jenkins/25770519#25770519

and This was what I did to solve it

sudo su jenkins -s /bin/bash

then once as jenkins user copy my ssh key to the server I want to connect/execute commands in, etc

ssh-copy-id myuser@TheRemoteserver.com

it then will present you this

myuser@TheRemoteserver.com's password: 
Now try logging into the machine, with "ssh 'myuser@TheRemoteserver.com'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

then I did this for testing purposes:

bash-4.1$ rsync -PSauve ssh --exclude=JenkinsBuild /srv/pd/* myuser@TheRemoteserver.com:/srv/pdc/test1  

and it passed without asking for password or anything. Notice that I'm still log as jenkins.

So now when I created the Jenkins job with some shell commands as part of the build it will work as expected :D

| improve this answer | | | | |
0

I had a similar problem.

In my case jenkins was not executing rsync with the expected user (jenkins) but with another (jboss in my case) adding 'whoami' to the script and using ssh verbose:

rsync -e "ssh -v" .......

helped to find the problem.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.