Issue
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
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!
Answered By - Andrés Cuadros
Answer Checked By - Marilyn (JavaFixing Volunteer)