What is the main purpose of publishing JUnit test reports in Jenkins pipelines?
Think about what Jenkins shows after tests run.
Publishing JUnit test reports allows Jenkins to parse test results and show them in the UI, helping teams monitor test success and failures over time.
Given this Jenkins pipeline snippet, what will Jenkins display after running the tests?
pipeline {
agent any
stages {
stage('Test') {
steps {
junit 'target/surefire-reports/*.xml'
}
}
}
}What does the junit step do with XML reports?
The junit step parses the XML test reports and displays a summary of test results in Jenkins, including counts of passed, failed, and skipped tests.
Which assertion correctly fails the Jenkins build if any JUnit test fails?
pipeline {
agent any
stages {
stage('Test') {
steps {
junit 'target/surefire-reports/*.xml'
// Assertion here
}
}
}
}Consider how Jenkins sets currentBuild.result after tests.
After the junit step, Jenkins sets currentBuild.result to 'UNSTABLE' if any test fails. The assertion should fail the build if the result is not 'SUCCESS'. Option A correctly checks this.
After running tests, Jenkins shows 'No test reports found'. What is the most likely cause?
Check the file path pattern used in the junit step.
If the junit step path does not match where the XML reports are saved, Jenkins cannot find and display test results, causing the 'No test reports found' message.
Which Jenkins pipeline snippet correctly archives JUnit test reports and fails the build if any test fails?
Consider where to check the build result and where to archive artifacts.
Option A archives artifacts in the post always block and checks currentBuild.result immediately after the junit step to fail the build if tests fail. This ensures proper sequencing and build failure on test failures.