Jenkins 2.89.3
Gradle 3.5
I'm running a build using a pipeline:
node {
try {
stage('Fetch code') {
echo 'Pulling the Code...'
checkout scm: [$class : 'GitSCM',
branches : [[name: '*/$GIT_CLOUD_BRANCH']],
browser : [$class: 'GitLab', repoUrl: cloudRepo, version: gitlabVersion],
doGenerateSubmoduleConfigurations: false,
submoduleCfg : [],
userRemoteConfigs : scm.userRemoteConfigs]
}
wrap([$class: 'Xvfb', screen: '1920x1080x24']) {
dir('BUILD') {
stage('Clean DB and old reports') {
sh '''chmod +x cleanup_old_reports.sh
./cleanup_old_reports.sh $PWD/../../builds $BUILD_NUMBER'''
}
stage('Build the application') {
sh '''chmod +x application.sh
./application.sh -P${PROJECT}'''
}
stage('Run tests') {
sh 'gradle clean run -P${PROJECT} -P${RUN_TYPE}'
}
}
}
stage('Generate reports') {
allure([includeProperties: false,
jdk : '',
properties : [],
reportBuildPolicy: 'ALWAYS',
results : [[path: 'ExaTAGS/TagsRunner/allure-results']]])
archive 'catalina.log'
}
} catch (Exception ex) {
currentBuild.result = "FAILURE"
println "in catch currentBuild.result: " + currentBuild.result
throw ex
} finally {
notifyBuild(currentBuild.result)
}
}
The stage 'Run tests' executes a gradle task RUN. In a case if there are any failed tests the main method of test runner throws an exception and RUN task returns exit code 1.
But despite this stage is marked as FAILED, the whole build is SUCCESSFUL:
I believe that RUN task actually does not throw an exception, cause I do not see the output I make in catch block in the pipeline script. But it really returns exit code different from 0, why does Jenkins ignore it? And what is the appropriate way to force Jenkins fail the whole build if there are any of failed stages?

Aucun commentaire:
Enregistrer un commentaire