Add failure mode to Jenkins pipeline

This commit is contained in:
RichardG867
2021-11-13 15:15:07 -03:00
parent b3972d11aa
commit d63461c712

65
.ci/Jenkinsfile vendored
View File

@@ -48,6 +48,8 @@ def saveArtifacts() {
archiveArtifacts artifacts: "${env.JOB_BASE_NAME}-*" archiveArtifacts artifacts: "${env.JOB_BASE_NAME}-*"
} }
def anySuccess = false
pipeline { pipeline {
agent any agent any
@@ -69,6 +71,10 @@ pipeline {
windowsBuild() windowsBuild()
saveArtifacts() saveArtifacts()
} }
script {
anySuccess = true
}
} }
} }
} }
@@ -81,38 +87,47 @@ pipeline {
unixBuild() unixBuild()
saveArtifacts() saveArtifacts()
} }
script {
anySuccess = true
}
} }
} }
} }
/* If we're on the main jobs, trigger each of the downstream jobs. */ /* This stage has two tasks:
stage('Trigger downstream jobs') { - Fail the build if all build stages failed
when { - Trigger downstream jobs if we're on the main job
expression { This could be done with two stages and when{} blocks, but then they
return env.JOB_BASE_NAME == '86Box-TestBuildPleaseIgnore'; would show up separately in the UI (unless JENKINS-44094 happens). */
} stage('Finish build') {
}
steps { steps {
script { script {
["${env.JOB_BASE_NAME}2"].each { if (env.JOB_BASE_NAME == '86Box-TestBuildPleaseIgnore') {
try { ["${env.JOB_BASE_NAME}2"].each {
/* Set next build number for this job. */ try {
def job = Jenkins.instance.getItem(it) /* Set next build number for this job. */
job.nextBuildNumber = env.BUILD_NUMBER as Integer def job = Jenkins.instance.getItem(it)
job.saveNextBuildNumber() job.nextBuildNumber = env.BUILD_NUMBER as Integer
} catch (Exception e) { job.saveNextBuildNumber()
println "[!] Could not set next build number for [$it], make sure all the script approvals are in place" } catch (Exception e) {
} println "[!] Could not set next build number for [$it], make sure all the script approvals are in place"
}
/* Trigger this job. */ /* Trigger this job. */
build propagate: false, build propagate: false,
wait: false, wait: false,
job: it, job: it,
parameters: [ parameters: [
string(name: 'BUILD_TYPE', value: BUILD_TYPE), string(name: 'BUILD_TYPE', value: BUILD_TYPE),
string(name: 'BRANCH', value: env.GIT_COMMIT) string(name: 'BRANCH', value: env.GIT_COMMIT)
] ]
}
}
if (!anySuccess) {
println "[!] Failing build because all build stages failed"
currentBuild.result = 'FAILURE'
} }
} }
} }