Jenkins Pipeline sshPublisher:如何获取execCommand的退出代码和输出?

时间:2019-03-01 19:54:52

标签: jenkins groovy jenkins-pipeline jenkins-plugins jenkins-groovy

使用Jenkins Pipeline's sshPublisher plugin(通过ssh发布)是否可以获得退出代码,并使用execCommand 运行命令的输出(在传输工件之后)结束)?

我正在使用插件,如下所示:

script {
    echo "Sending artifacts to machine at " + remoteDirectory

    // Use of the ssh publisher plugin over SSH
    sshPublisher(
        failOnError: false,
        publishers: [
            sshPublisherDesc(
                configName: "my-drive",
                transfers: [
                    sshTransfer(
                        sourceFiles: mySourceFilesList,
                        remoteDirectory: remoteDirectory,
                        flatten: true,
                        execCommand: commandToExec,
                        execTimeout: 1800000
                    )
                ],
                sshRetry: [
                    retries: 0
                ]
            )
        ]
    )
    // How can I get the output of execCommand?
    // If the exit code was 1, I want to perform some special steps
    // I'd also like to include the output of the command in these steps
}

维基页面here说(这是古老的,但从2011年开始):

  

命令执行中的STDOUT和STDERR记录在   Jenkins控制台。

1 个答案:

答案 0 :(得分:1)

这是“否”(不确定,但是我会尽力而为)。
现在我对这个脚本ssh user@nas01 su -c "/path/to/command1 arg1 arg2"

感到满意