'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.



Solution 1:[1]

Keep in mind that if the sshCommand fails, it will not return anything. You can work around this by running sshCommand with 'failOnError: false' flag and then processing the return yourself.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Konstantin