Skip to content
SDETRole
SDETRole

Jenkins interview question

How do you publish test results in Jenkins, and what is the difference between UNSTABLE and FAILURE?

intermediate 2–5 yrs #reporting#junit#artifacts

Short answer

Have the runner write JUnit XML, publish it in a post { always } block with the junit step, and archive HTML reports, screenshots and traces as artifacts. The junit step marks the build UNSTABLE when tests fail; FAILURE means the pipeline itself broke, such as a compile error or crash.

Answer

Jenkins does not understand test frameworks directly. It understands JUnit XML, which almost every runner can produce: Maven Surefire/Failsafe, Gradle, TestNG, pytest (--junitxml), Playwright and Cypress (via reporters), Newman. So the pattern is: make the runner write XML, publish it with the junit step, and archive everything else a human needs to debug a failure.

The pipeline pattern

pipeline {
    agent { label 'linux' }
    stages {
        stage('Test') {
            steps {
                // Let Maven finish even if tests fail, so reports are complete
                sh 'mvn -B verify -Dmaven.test.failure.ignore=true'
            }
        }
    }
    post {
        always {
            junit testResults: '**/target/surefire-reports/*.xml, **/target/failsafe-reports/*.xml',
                  allowEmptyResults: false
            archiveArtifacts artifacts: 'target/screenshots/**, target/logs/**',
                             allowEmptyArchive: true,
                             fingerprint: false
        }
        failure {
            echo 'Pipeline failed before or outside test execution'
        }
    }
}

Two details matter here:

  • post { always { } }: if publishing lives inside the test stage and the shell step exits non-zero, Jenkins aborts the stage and the reports are never recorded. always runs regardless.
  • Exit codes: most runners exit non-zero when a test fails. Either tell the tool to ignore test failures (Maven’s -Dmaven.test.failure.ignore=true), or capture the status with sh(script: '...', returnStatus: true) and let the junit step decide the result.

UNSTABLE vs FAILURE

  • UNSTABLE (yellow): the build ran to completion but the junit step found failing tests. The product may be broken; the pipeline is fine.
  • FAILURE (red): the pipeline itself failed, such as a compilation error, a missing dependency, an agent going offline, or a step returning a non-zero exit code that nobody handled.

This distinction is useful in triage. Red means “look at the build or infrastructure”, yellow means “look at the test results”. If every test failure shows up as red, the team loses that signal. You can also set results explicitly, for example unstable('Quarantined tests failed') or catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') { ... } for a non-blocking stage.

Rich reports and debugging artifacts

The junit step gives trends, per-test history and failure age, which helps spot flaky tests. For more detail, archive an HTML report and publish it with the HTML Publisher plugin or the Allure plugin, and archive screenshots, videos, Playwright traces and service logs. Keep artifact retention bounded with buildDiscarder so disk usage does not grow forever.

Common mistakes

  • Publishing results only on success.
  • allowEmptyResults: true everywhere, which hides a broken reporter as a green build.
  • Archiving gigabytes of video for passing tests instead of only on failure.

What interviewers look for

  • JUnit XML plus the junit step in post { always }.
  • A clear explanation of UNSTABLE vs FAILURE and why it matters for triage.
  • Awareness of exit-code handling and debugging artifacts.

A strong answer covers

  • Generate JUnit XML and publish it with the junit step
  • Publish in post always so results appear even when tests fail
  • UNSTABLE means test failures; FAILURE means the build or pipeline broke
  • Archive screenshots, traces, logs and HTML reports as artifacts
  • Exit code handling so failing tests do not abort report publishing
Practise answering under time pressure

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →