From d9f0f758533f59e3bee419960d3df57e73fa8889 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Wed, 8 Mar 2023 16:34:30 +0100 Subject: [PATCH 1/6] Add check on exit status code on deploy job method --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index ef64a66..493decd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -277,6 +277,9 @@ def deploy(String service, String version, String host){ echo " last exit code \$?"; """) println("Deploy ended with status: "+statusCode); + if (statusCode > 0){ + currentBuild.buildResult= 'FAILURE' + } } //Implement a new method in order to check the input parameters -- 2.17.1 From 85a02129595037060b0b56b535c9b770d3520ff7 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Wed, 8 Mar 2023 16:51:12 +0100 Subject: [PATCH 2/6] add error call in order to stop the whole pipeline if an error occur --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 493decd..5479f1b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -279,6 +279,7 @@ def deploy(String service, String version, String host){ println("Deploy ended with status: "+statusCode); if (statusCode > 0){ currentBuild.buildResult= 'FAILURE' + error("Ansible run failed with the following statusCode "+statusCode) } } -- 2.17.1 From 793a27a3c04bd345ccc2018e0d5077e641c1ffc7 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Wed, 8 Mar 2023 16:54:59 +0100 Subject: [PATCH 3/6] set build to unstable for testing --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5479f1b..d1b3927 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -278,7 +278,7 @@ def deploy(String service, String version, String host){ """) println("Deploy ended with status: "+statusCode); if (statusCode > 0){ - currentBuild.buildResult= 'FAILURE' + currentBuild.buildResult= 'UNSTABLE' error("Ansible run failed with the following statusCode "+statusCode) } } -- 2.17.1 From 8a09f1184a2b24d486296325326f40ad0fc59ab5 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Wed, 8 Mar 2023 16:57:18 +0100 Subject: [PATCH 4/6] REMOVE CATCH FROM DEPLOY JOB STAGE --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d1b3927..aba604e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -193,10 +193,10 @@ pipeline { script{ echo "Cron build disabled. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} ongoing" ansiColor("xterm") { - catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { + // catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { checkup("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}"); deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}"); - } + // } } } -- 2.17.1 From f44949695ff2022e1942863d6448e6468d9004ae Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Wed, 8 Mar 2023 17:01:20 +0100 Subject: [PATCH 5/6] add catch on deploy job stage but now with buildResult set to unstable --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index aba604e..01ce0c4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -193,10 +193,10 @@ pipeline { script{ echo "Cron build disabled. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} ongoing" ansiColor("xterm") { - // catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { + catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { checkup("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}"); deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}"); - // } + } } } -- 2.17.1 From a0ff479a1b9c223df32ba7b77d68043b5cf1b2dc Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Wed, 8 Mar 2023 17:04:38 +0100 Subject: [PATCH 6/6] remove some print on deploy job method --- Jenkinsfile | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 01ce0c4..1ead091 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -273,14 +273,6 @@ def deploy(String service, String version, String host){ def now = new Date(); println("Going to deploy the service "+service+" with version: "+version+" on target: "+host); def statusCode = sh( script: "cd $ANSIBLE_ROOT_FOLDER;./deployService.sh $service $version $host;", returnStdout: true); - sh(""" - echo " last exit code \$?"; - """) - println("Deploy ended with status: "+statusCode); - if (statusCode > 0){ - currentBuild.buildResult= 'UNSTABLE' - error("Ansible run failed with the following statusCode "+statusCode) - } } //Implement a new method in order to check the input parameters -- 2.17.1