Sometimes unit tests get skipped due to various reasons[1]. If that happens I notice it when I look at the report, which I sometimes don't do for several weeks. Instead I want jenkins to mark the build as unstable, so I notice sooner that something is up.

Here is what my stage looks like.

stage('Unit tests') {
    steps {
        sh 'run_tests.sh'
    post  {
        always {
            junit 'reports/unit/xunit.xml'
            // the next line doesn't work because the property "currentBuild.junit_tests_skipped" does't exist. 
            // if (currentBuild.junit_tests_skipped > 10){
            //     currentBuild.result = "UNSTABLE"
            // }

How would I modify this example so that skipped tests would cause the build to be marked as "unstable"?

[1]: Sometimes this is intentional. Sometimes this happens because of a changed configurations. Sometimes this happens when something weird happens (e.g. when test setup fails, as commented here). In my specific project selenium tests gets skipped when the chromedriver doesn't match the installed chrome-version anymore, which happens for reasons outside the project.

This is not a duplicate of this question because that question and its answer heavily rely on org.junit.Assume, which I don't. Also I don't want to change how my tests are executed (e.g. when I run the test-suite on a dev-machine without the correct version of chrome installed, I still want them to be skipped without raising errors)

  • Isn't it a junit question and not Jenkins?
    – Rsf
    Jun 9 at 15:37


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.