Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do ssh to remote server from Jenkins

Tags:

ssh

jenkins

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 
like image 615
Karthika Avatar asked Oct 14 '25 08:10

Karthika


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"
  }
}
like image 192
VonC Avatar answered Oct 18 '25 01:10

VonC