Jenkins Pipeline: How to archive artifacts when assembly fails?

When our browser-based tests fail, we will take a screenshot in the browser window to better illustrate the problem. However, I do not understand how to archive them in my pipeline, because the pipeline stops after a failure. The same for junit.xml, I would also like to use it in cases of errors.

I checked, screenshots are created and saved correctly.

My definition is as follows (irrelevant things are mostly trimmed):

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/*'
   }
}
+4
source share
2 answers

Java try/catch, , Jenkins catchError :

node {
    catchError {
        // Tests that might fail...
    }
    // Archive your tests artifacts
}
+2

, :

pipeline {
    agent any
    stages {
        stage('Build') {
            ...
        }
        stage('Test') {
            ...
        }
    }

    post {
        always {
            archive 'build/libs/**/*.jar'
        }
    }
}
+1

Source: https://habr.com/ru/post/1654787/


All Articles