title: Jenkins Pipeline sshPublisher: How to get exit code and output of execCommand?
body: <p>Using <a href="https://jenkins.io/doc/pipeline/steps/publish-over-ssh/" rel="noreferrer">Jenkins Pipeline's sshPublisher plugin</a> ("publish over ssh"), is it possible to get the <strong>exit code and output of the command ran with <code>execCommand</code></strong> (after artifacts have been transferred over)?</p>
  
  <p>I'm using the plugin as follows:</p>
  
  <pre><code>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
  }
  </code></pre>
  
  <p>The wiki page <a href="https://wiki.jenkins.io/pages/viewpage.action?pageId=59507121" rel="noreferrer">here</a> says (this is old and from 2011 though):</p>
  
  <blockquote>
    <p>STDOUT and STDERR from the command execution are recorded in the
    Jenkins console.</p>
  </blockquote>