From 97caed1d340e56fc52d8d049551835bb4faa2592 Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Fri, 10 Jan 2020 18:16:23 +0000 Subject: [PATCH] Avoid use of switch on String for Checks API results After the recent upgrades of Jenkins and the pipeline-related plugins, the Groovy switch on string for the build results conversion into the Checkers result returned null causing build failures. Use the safer if/then/else construct that works also with the latest Groovy/CPS sandbox. Change-Id: Ibb4ea9d8b6669a548be1826519deaf008304dcf6 --- Jenkinsfile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 085cc65748..f2d361e6f3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -63,17 +63,15 @@ class GerritCheck { } def getCheckResultFromBuild() { - switch(build.result) { - case 'SUCCESS': - return "SUCCESSFUL" - case 'NOT_BUILT': - case 'ABORTED': - return "NOT_STARTED" - case 'FAILURE': - case 'UNSTABLE': - default: - return "FAILED" + def resultString = build.result.toString() + if (resultString == 'SUCCESS') { + return "SUCCESSFUL" + } else if (resultString == 'NOT_BUILT' || resultString == 'ABORTED') { + return "NOT_STARTED" } + + // Remaining options: 'FAILURE' or 'UNSTABLE': + return "FAILED" } }