Better error handling for docker image sub-jobs
Currently Jenkinsfile ignores failures in sub-jobs related to docker images (base image, wheels, etc). If they fail, the overall build remains successful. This allows docker-related build problems remain unnoticed. Make this behavior conditional on a job parameter. TESTS ============================================== * A build where there are no docker-related errors (overall: SUCCESS) * A build where wheels fail and SUPPRESS_DOCKER_IMAGE_BUILD_ERRORS is true (overall: SUCCESS) * A build where wheels fail and SUPPRESS_DOCKER_IMAGE_BUILD_ERRORS is false (overall: FAIL) Story: 2009895 Task: 47280 Signed-off-by: Davlet Panech <davlet.panech@windriver.com> Change-Id: I16ac4f63033ecbc78c647c4da105d550fe2facc4
This commit is contained in:
parent
876db849e9
commit
7481a3b257
|
@ -29,7 +29,7 @@ def parseProps(text) {
|
|||
def loadEnv() {
|
||||
def data = {}
|
||||
data.NEED_BUILD = false
|
||||
data.SUPPRESS_DOCKER_IMAGE_BUILD_ERRORS = true
|
||||
data.SUPPRESS_DOCKER_IMAGE_BUILD_ERRORS = params.SUPPRESS_DOCKER_IMAGE_BUILD_ERRORS
|
||||
ws(params.BUILD_HOME) {
|
||||
if (fileExists ("NEED_BUILD")) {
|
||||
data.NEED_BUILD = true
|
||||
|
@ -51,32 +51,43 @@ def partJobName (name) {
|
|||
return "/" + folder + "parts/" + name
|
||||
}
|
||||
|
||||
def runPart (name, params = []) {
|
||||
def runPart (name, params = [], propagate = true) {
|
||||
// Tell Jenkins to checkout the same commit of the sub-job's Jenkinsfile,
|
||||
// as the current builds' Jenkinsfile's commit.
|
||||
final gitRef = string (name: 'JENKINS_SCRIPTS_BRANCH', value: env.GIT_COMMIT)
|
||||
build job: partJobName (name), parameters: copyCurrentParams() + [ gitRef ] + params
|
||||
return build (
|
||||
job: partJobName (name),
|
||||
parameters: copyCurrentParams() + [ gitRef ] + params,
|
||||
propagate: propagate
|
||||
)
|
||||
}
|
||||
|
||||
def runImagesPart (name, params = []) {
|
||||
if (!IMAGES_FAILED) {
|
||||
final jobName = partJobName (name)
|
||||
final res = build (
|
||||
job: jobName,
|
||||
parameters: copyCurrentParams() + IMG_PARAMS + params,
|
||||
propagate: ! PROPS.SUPPRESS_DOCKER_IMAGE_BUILD_ERRORS
|
||||
).result
|
||||
if (res == 'ABORTED') {
|
||||
// FIXME: make current build ABORTED here
|
||||
error ("child job ${jobName} aborted")
|
||||
// Ignore docker image - related errors. In this case We
|
||||
// prevent sub-jobs from raising exceptions and failing the
|
||||
// current build. Instead we note when an image-related
|
||||
// job has failed, and skip all subsequent image-related
|
||||
// jobs.
|
||||
if (PROPS.SUPPRESS_DOCKER_IMAGE_BUILD_ERRORS) {
|
||||
if (!IMAGES_FAILED) {
|
||||
final jobName = partJobName (name)
|
||||
final res = runPart (name, IMG_PARAMS + params, false).result
|
||||
if (res == 'ABORTED') {
|
||||
// FIXME: make current build ABORTED here
|
||||
error ("child job ${jobName} aborted")
|
||||
}
|
||||
if (res == 'SUCCESS' || res == 'UNSTABLE') {
|
||||
return true
|
||||
}
|
||||
print ("*** ERROR: child job ${jobName} failed!")
|
||||
IMAGES_FAILED = true
|
||||
}
|
||||
if (res == 'SUCCESS' || res == 'UNSTABLE') {
|
||||
return true
|
||||
}
|
||||
print ("*** ERROR: child job ${jobName} failed!")
|
||||
IMAGES_FAILED = true
|
||||
return false
|
||||
}
|
||||
return false
|
||||
// Otherwise, just call the subjob normally - ie its failure
|
||||
// will propagate to the current build
|
||||
runPart (name, IMG_PARAMS + params)
|
||||
return true
|
||||
}
|
||||
|
||||
def printBuildFooter() {
|
||||
|
@ -197,6 +208,10 @@ pipeline {
|
|||
booleanParam (
|
||||
name: 'PUSH_DOCKER_IMAGES'
|
||||
)
|
||||
booleanParam (
|
||||
name: 'SUPPRESS_DOCKER_IMAGE_BUILD_ERRORS',
|
||||
defaultValue: false
|
||||
)
|
||||
booleanParam (
|
||||
name: 'IMPORT_BUILD'
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue