Rsync to Google Compute engine Instance from Jenkins

first configure .ssh config file by (assuming you installed gcloud sdk):

gcloud compute config-ssh

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

ssh your-instance

your-instance is in the form of "instance.zone.project", usually.

Now you can rsync:

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

Done.

You can mention the user if you like so:

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

It worked for me. Juts do not forget to replace "your-instance" (and your-user) with the correct one. You can get it through "gcloud compute config-ssh" or "gcloud compute config-ssh --dry-run" or go to your cloud.google.com then compute engine then vm instances then from connect choose view gcloud command. All will show your instance name in the form of "instance.zone.project."

I hope it will help someone in future. :)


Maybe a little late, but you can use the gcloud compute ssh command directly instead of finding the google ssh keys.

First, you have to make a script that will hide the rsync ssh command args 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 to your heart's content:

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

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