Jenkins Pipeline: How to archive artifacts when the build fails?
<p>When our browser based tests fail, we take a screenshot of the browser window to better illustrate the problem. However, I don't understand how to archive them in my pipeline, because the pipeline stops after the failure. Same for the <code>junit.xml</code>, I'd also like to use it in error cases.</p>

<p>I've checked, the screenshots are generated and stored correctly.</p>

<p>My definition looks like this (irrelevant things mostly trimmed):</p>

<pre><code>node {
   stage('Build docker container') {
       checkout([$class: 'GitSCM', ...])
       sh "docker build -t webapp ."
   }
   stage('test build') {
       sh "mkdir -p rspec screenshots"
       sh "docker run -v /var/jenkins_home/workspace/webapp/rspec/junit.xml:/myapp/junit.xml -v /var/jenkins_home/workspace/webapp/screenshots:/myapp/tmp/capybara -v webapp bundle exec rspec"
   }
   stage('Results') {
      junit 'rspec/junit*.xml'
      archive 'screenshots/*'
   }
}
</code></pre>