Search code examples
jenkinssshrsync

Running rsync from jenkins shell script


I'm just starting out with jenkins and I'm having trouble to connect to a remote machine via rsync.

I guess jenkins doesn't know which ssh identity file to use or maybe it knows, but doesn't know how to decrypt it? From other questions i gathered that the Gtk-Warning is probably because it can't open the "enter keyphrase"-prompt.

rsync -azvh /var/lib/jenkins/workspace/ofen sascha@my_server:/my_project/ofen
No protocol specified

(ssh-askpass:19928): Gtk-WARNING **: cannot open display: :0
Host key verification failed.
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]

Everything works fine when I try it from commandline.


Solution

  • Need to have the key loaded as part of Jenkin's SSH Agent configuration.

    1. Add the private key to Jenkins via credentials/SSH private key including pass phrase if one is used
    2. Enable SSH agent on the job and give it the credential

    Things that use SSH keys and agents can now use the loaded key.