How to do ssh to remote server from Jenkins

Viewed 9425

Can anyone let me know how to connect remote server from Jenkins (server1). That is, how to do ssh via command line and a job?

sudo ssh user@server2 
1 Answers

For freestyle jobs, you would use the Jenkins SSH plugin.

https://wiki.jenkins.io/download/attachments/42470275/ssh-global-cfg.png?version=1&modificationDate=1267072997000&api=v2

https://wiki.jenkins.io/download/attachments/42470275/ssh-job-cfg.png?version=1&modificationDate=1267072997000&api=v2

For pipelines, you have pipeline SSH steps which does the same:

node {
  def remote = [:]
  remote.name = 'test'
  remote.host = 'test.domain.com'
  remote.user = 'root'
  remote.password = 'password'
  remote.allowAnyHosts = true
  stage('Remote SSH') {
    sshCommand remote: remote, command: "ls -lrt"
    sshCommand remote: remote, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"
  }
}
Related