Jenkins sshagent execution not working

Eldo picture Eldo · Feb 9, 2017 · Viewed 7.2k times · Source

I am trying to use sshagent options to scp/ftp files to windows and linux serers but it is not working as expected, could someone help me on this?

What should be credentials? I used encrypted userid and password value created using jenkins. What should be the command to execute to scp file to server1?

Answer

okapi picture okapi · Feb 16, 2017

You can't store a userid/password combination in an ssh agent, only a private key.

Under Jenkins -> Credentials -> System -> Global credentials in the Jenkins web interface, you can add new credentials. Go for an SSH username with private key in global scope. You can use ssh-keygen to make thew private key. Then your pipeline can do something like:

sshagent (credentials: ['58754abf756cd-6057-.....']) {
  sh 'scp file host:dir'
}

Note that the SSH agent is a plugin that needs installing.