title: How do I fail a Jenkins build if a Docker Pipeline Plugin withRun command returns a non-zero exit code?
body: <p>I'm using the <a href="https://wiki.jenkins-ci.org/display/JENKINS/Docker+Pipeline+Plugin" rel="nofollow noreferrer">Docker Pipeline Plugin</a> to execute my build scripts via Docker containers. I noticed that if I had a script return a non-zero exit code when executing within an <code>inside()</code> command, Jenkins would mark the pipeline execution as a failure. This example Jenkinsfile illustrates that scenario:</p>
  
  <pre><code>docker.image('alpine').inside() {
    sh 'exit 1'
  }
  </code></pre>
  
  <p>However, if I use the <code>withRun()</code> command, a similar Jenkinsfile will <em>not</em> cause the build to fail, even though the <code>docker ps -l</code> command shows that the container exited with a non-zero status:</p>
  
  <pre><code>node() {
    sh 'touch ./test.sh'
    sh 'echo "exit 1" &gt;&gt; ./test.sh'
    sh 'chmod 755 ./test.sh'
  
    docker.image('alpine').withRun("-v ${WORKSPACE}:/newDir", '/bin/sh /newDir/test.sh') {container -&gt;
      sh "docker logs ${container.id} -f"
      sh 'docker ps -l'
    }
  }
  </code></pre>
  
  <p>Is there a way to make <code>withRun()</code> fail the build if the container exits with a non-zero code?</p>