Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ssh-steps output from Jenkins pipeline

I am quite new with Jenkins, so maybe question is obvious.

I have Jenkins on Windows machine, and I need to run the command on remote nix machine, where I have an ssh access (by username / password). I have a pipeline and using ssh-steps plugin for pipeline I could connect and execute command, but I need to get output of command to go forward, and I couldn't find a correct way to do it.

def remote = [:]
remote.name = 'UAT'
remote.host = 'test.domain'
remote.user = 'username'
remote.password = 'pass'
remote.allowAnyHosts = true
stage('Remote SSH') {
  sshCommand remote: remote, command: "ls -ll"
}

Is it possible to do it with this plugin or I need to use another one? As I understand, this plugin is specially created for using ssh in pipeline script.

like image 529
MoGol Avatar asked Dec 23 '22 20:12

MoGol


1 Answers

Try this:

def remote = [:]
remote.name = 'UAT'
remote.host = 'test.domain'
remote.user = 'username'
remote.password = 'pass'
remote.allowAnyHosts = true
stage('Remote SSH') {
   def commandResult = sshCommand remote: remote, command: "ls -ll"
   echo "Result: " + commandResult
}

It's not easy to figure out because is not documented!

like image 137
Andrés Cuadros Avatar answered Dec 26 '22 11:12

Andrés Cuadros