Complete the code to publish JUnit test reports in a Jenkins pipeline.
post {
always {
junit '[1]'
}
}The junit step in Jenkins expects the path to the XML test report files. The pattern **/target/surefire-reports/*.xml matches the default location of JUnit reports generated by Maven.
Complete the code to archive JUnit test reports as artifacts after the build.
steps {
archiveArtifacts artifacts: '[1]', allowEmptyArchive: true
}The archiveArtifacts step archives files as build artifacts. To archive JUnit reports, use the XML files in the surefire-reports directory.
Fix the error in the Jenkins pipeline snippet to correctly publish JUnit test reports.
post {
always {
junit '[1]'
}
}The junit step requires XML report files. Using HTML or TXT files will cause errors. The pattern **/target/surefire-reports/*.xml ensures all XML reports in any subdirectory are included.
Fill both blanks to define a Jenkins pipeline stage that runs tests and publishes JUnit reports.
stage('Test') { steps { sh '[1]' junit '[2]' } }
The sh 'mvn test' command runs the tests using Maven. The junit step then publishes the XML reports generated in the surefire-reports folder.
Fill all three blanks to create a Jenkins pipeline snippet that runs tests, archives reports, and publishes JUnit results.
stage('Test') { steps { sh '[1]' archiveArtifacts artifacts: '[2]', allowEmptyArchive: true junit '[3]' } }
This pipeline stage runs tests with Maven, archives the XML reports as artifacts, and publishes the JUnit test results from the surefire-reports directory.