У меня есть Jenkinsfile
:
node{
stage ('Checkout')
{
checkout scm
}
stage ('Build')
{
try {
sh '''
mvn clean -B org.jacoco:jacoco-maven-plugin:prepare-agent install
'''
} catch (err) {
// do nothing
currentBuild.result = 'FAILED'
} finally {
//step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1,
thresholds: [
[$class: 'FailedThreshold', unstableThreshold: '2'],
[$class: 'SkippedThreshold', unstableThreshold: '']],
tools: [
[$class: 'JUnitType', deleteOutputFiles: false, failIfNotNew: false, pattern: '**/target/surefire-reports/TEST-*.xml', skipNoTestFiles: true, stopProcessingIfError: false]]
])
}
}
}
Я хочу пометить сборку как UNSTABLE
, когда: некоторые тесты не пройдены с использованием порога подключаемого модуля xUnit, и я хочу отметить его FAILED
, если в коде есть какая-либо ошибка, такая как синтаксическая ошибка.
Проблема здесь в том, что catch
выполняется в обеих ситуациях: ошибка кода и сбой теста. Как я могу настроить Jenkinsfile
, чтобы изменить ситуацию?
После запуска сборки, в которой было 3 ошибки теста (порог 2), я ожидал, что сборка будет UNSTABLE
, но она превратилась в FAILED
:
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing JUnit
[xUnit] [INFO] - [JUnit] - 1 test report file(s) were found with the pattern '**/target/surefire-reports/TEST-*.xml' relative to '/var/lib/jenkins/workspace/jenkins-failure_master-EHKMAGGDJWHA7FNGHQYY2VJNJHBX2RXI3XJY4NU5EB2PYT4ERTZQ' for the testing framework 'JUnit'.
[xUnit] [INFO] - Check 'Failed Tests' threshold.
[xUnit] [INFO] - The total number of tests for this category exceeds the specified 'unstable' threshold value.
[xUnit] [INFO] - Setting the build status to FAILURE
[xUnit] [INFO] - Stopping recording.
Новый случай: я прокомментировал строку currentBuild.result = 'FAILED'
и добавил синтаксическую ошибку в тестовом классе. Сборка выполнена успешно даже с COMPILATION ERROR
и тесты пропущены:
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing JUnit
[xUnit] [INFO] - [JUnit] - No test report file(s) were found with the pattern '**/target/surefire-reports/TEST-*.xml' relative to '/var/lib/jenkins/workspace/jenkins-failure_master-EHKMAGGDJWHA7FNGHQYY2VJNJHBX2RXI3XJY4NU5EB2PYT4ERTZQ' for the testing framework 'JUnit'. Did you enter a pattern relative to the correct directory? Did you generate the result report(s) for 'JUnit'?
[xUnit] [WARNING] - No test reports found for the metric 'JUnit' with the resolved pattern '**/target/surefire-reports/TEST-*.xml'.
[xUnit] [INFO] - Skipping the metric tool processing.
[xUnit] [INFO] - There are errors when processing test results.
[xUnit] [INFO] - Skipping tests recording.