Skip to content

Reporting test results and storing artifacts

Patrick O'Hannigan edited this page Nov 15, 2016 · 9 revisions

If you have a test runner (such as maven surefire, or many of the javascript runners) chances are it can output the junit/xml style of test result reports. If so, recording them is easy:

postBuild {
  always {
    junit "path/to/xml"
  }
}

This will always grab the test results and let Jenkins track them, calculate trends, and report on them. Jenkins has plugins for pretty much all other types of test runners too. A build that has failing tests is marked as UNSTABLE (to separate it from FAILED).

<<<<<<< HEAD If you want to store an artifact for downloading later (ie keep a record of it):

If you want to store an artifact for downloading later (i.e., keep a record of it):

origin/master

postBuild {
   success {
      archive "target/**/*"
   }
}

You can also run actions, such as notifications, artifact archiving, or any arbitrary step, after individual stages:

stage('some-stage') {
    steps {
        sh 'do-something.sh'
    }
    postBuild {
        failure {
            sh 'rollback.sh'
        }
    }
}

A more complete example:

pipeline {
    agent docker:"java"
    stages {
        stage("build") {
            steps {
                sh 'mvn clean install -Dmaven.test.failure.ignore=true'
            }
        }
    }
    postBuild {
        always {
            archive "target/**/*"
            junit 'target/surefire-reports/*.xml'
        }
    }
}

Clone this wiki locally