Rsync to Google Compute Instance by Jenkins

I want to send files from Jenkins to my instance on a Google Compute engine instance. I added the assembly to my config in jenkins:

rsync -vrzhe "ssh -i /var/lib/jenkins/.ssh/google_compute_engine -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no" . login@Host:/var/www

      

And I am getting this error:

Checking out Revision 59cf9dd819fe2168c4c40f716707d58b2b99e251 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 59cf9dd819fe2168c4c40f716707d58b2b99e251
> git rev-list 59cf9dd819fe2168c4c40f716707d58b2b99e251 # timeout=10
[Platform] $ /bin/sh -xe /tmp/hudson4502433356962914860.sh
+ rsync -vrzhe 'ssh -i /var/lib/jenkins/.ssh -o UserKnownHostsFile=/dev/null -o 

      


CheckHostIP=no -o StrictHostKeyChecking=no' . login@Host:/var/www
   StrictHostKeyChecking=no' . login@host:/var/www
   ssh: connect to host host port 22: Connection timed out
   rsync: connection unexpectedly closed (0 bytes received so far) [sender]
   rsync error: unexplained error (code 255) at io.c(601) [sender=3.0.7]
   Build step 'ExΓ©cuter un script shell' marked build as failure
   Finished: FAILURE

      

Any idea

+4


source to share


5 answers


The problem was my public key to solve the problem you want:

1 - Setting up your ssh keys: execute

gcloud compute ssh example-instance

      



2 - cp your .ssh / google_compute_engine.pub file to an authorized GCE VM page

3 - restart the virtual machine instance

thanks for the help

+1


source


first set up your .ssh config file (assuming you have installed gcloud sdk):

gcloud compute config-ssh

      

It will tell you that "you can now use ssh / scp with your instances by running

ssh your-instance

      

your instance is usually in the form "instance.zone.project".

Now you can rsync:



rsync -ave ssh your-local-dir your-instance:~/your-destination

      

Done.

You can specify the user if you like it:

rsync -ave ssh your-local-dir your-user@your-instance:~/your-destination

      

This worked for me. Juts don't forget to replace "your instance" (and your user) with the correct one. You can get it via "gcloud compute config-ssh" or "gcloud compute config-ssh -dry-run" or go to your cloud.google.com then compute engine and then vm instances and then from connect select gcloud command view. Everything will display your instance name in the form "instance.zone.project".

I hope this helps someone in the future. :)

+11


source


The rsync command above uses the -i option to ssh. The argument to the -i option must be the path to the ssh key file, not the directory where the key file is located.

+2


source


Maybe a little late, but you can use the command gcloud compute ssh

directly instead of finding google ssh keys.

First, you have to make a script that will hide the rsync ssh commands from gcloud:

cat >./gcloud-compute-ssh <<EOF
#! /bin/sh
host="$1"
shift
exec gcloud compute ssh "$host" -- "$@"
EOF

chmod a+x ./gcloud-compute-ssh

      

Then you can rsync -e

add your heart:

rsync -e ./gcloud-compute-ssh my-dir my-instance:/my-dir

      

+2


source


As mentioned in " How to resolve rsync error: error in rsync protocol data stream (code 12) in io.c (600) on windows ", check which ssh is actually being used and if that version of ssh is compatible with one of the rsync s.

Specifying an absolute path for the ssh executable can help:

rsync -e /usr/bin/ssh .... 

      

This thread also offers to clear ~/.ssh/know_hosts

if the server has changed and now has a different key.

0


source







All Articles