从 Jenkins 管道获取 ssh-steps 输出

MoG*_*Gol 3 jenkins jenkins-plugins jenkins-pipeline

我对詹金斯很陌生,所以也许问题很明显。

我在 Windows 机器上有 Jenkins,我需要在远程 nix 机器上运行命令,在那里我有 ssh 访问权限(通过用户名/密码)。我有一个管道并使用 ssh-steps 插件作为管道我可以连接和执行命令,但是我需要获得命令的输出才能继续前进,但我找不到正确的方法来做到这一点。

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"
}
Run Code Online (Sandbox Code Playgroud)

是否可以使用此插件来实现,或者我需要使用另一个插件?据我了解,这个插件是专门为在管道脚本中使用 ssh 而创建的。

And*_*rez 8

尝试这个:

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
}
Run Code Online (Sandbox Code Playgroud)

这不容易弄清楚,因为没有记录!