Move Jenkins post-build tasks to a post{} block

This commit is contained in:
RichardG867
2021-11-13 15:59:22 -03:00
parent 94d9ec1414
commit 913b695073

59
.ci/Jenkinsfile vendored
View File

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