From 15b75dea9dd866d6dec50a664f408883dac43718 Mon Sep 17 00:00:00 2001 From: "roberto.cirillo" Date: Wed, 5 Oct 2022 09:59:20 +0200 Subject: [PATCH 1/2] extract deployPendingJobs method from DeployFromSystem stage --- Jenkinsfile | 63 +++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e1b489a..e440a6c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -93,34 +93,7 @@ pipeline { echo 'Cron build enabled. Deploy from system ongoing' script { def deployFolder="CD-${env.BUILD_NUMBER}"; - println ("searching files in folder ${deployFolder}"); - def files = findFiles(glob: "${deployFolder}/*.csv") - if (files == null){ - println ("Nothing to do"); - }else{ - def serviceList = [] - for (def file : files){ - def records = readCSV file: "${file.path}" - for (def record : records) { - println("Processing record: "+record) - if(!serviceList.contains(record.get(0))){ - stage(record.get(0)){ - println "Deploy on going of component: ${record.get(0)}" - catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') { - checkup(record.get(0), record.get(1), record.get(2)); - deploy(record.get(0), record.get(1), record.get(2)); - } - } - serviceList << record.get(0) - }else{ - echo "${record.get(0)} already deployed. Deployment skipped." - } - - } - sh "rm ${file.path}" - } - sh "rm -Rf ${deployFolder}" - } + deployPendingJobs(deployFolder); } @@ -257,3 +230,37 @@ def checkup(String service, String version, String host){ esac """) } + + +//parse all csv files found in the local folder and deploy the components defined inside +def deployPendingJobs( def deployFolder){ + println ("searching files in folder ${deployFolder}"); + def files = findFiles(glob: "${deployFolder}/*.csv") + if (files == null){ + println ("Nothing to do"); + }else{ + def serviceList = [] + for (def file : files){ + def records = readCSV file: "${file.path}" + for (def record : records) { + println("Processing record: "+record) + if(!serviceList.contains(record.get(0))){ + stage(record.get(0)){ + println "Deploy on going of component: ${record.get(0)}" + catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') { + checkup(record.get(0), record.get(1), record.get(2)); + deploy(record.get(0), record.get(1), record.get(2)); + } + } + serviceList << record.get(0) + }else{ + echo "${record.get(0)} already deployed. Deployment skipped." + } + + } + sh "rm ${file.path}" + } + sh "rm -Rf ${deployFolder}" + } +} + From 724a1b62281b10992cc4c8c722d3c235ed6cfc8a Mon Sep 17 00:00:00 2001 From: "roberto.cirillo" Date: Wed, 5 Oct 2022 10:21:20 +0200 Subject: [PATCH 2/2] rename var IS_CRON with IS_SCHEDULED --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e440a6c..049bfe4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -86,7 +86,7 @@ pipeline { allOf{ triggeredBy 'TimerTrigger' // maybe we can add a new condition in order to consider the manual execution of this pipeline - environment name: 'IS_CRON_TMP', value: 'True' + environment name: 'IS_SCHEDULED', value: 'True' } } steps { @@ -104,7 +104,7 @@ pipeline { anyOf{ allOf{ triggeredBy 'TimerTrigger' - environment name: 'IS_CRON_TMP', value: 'False' + environment name: 'IS_SCHEDULED', value: 'False' } } @@ -115,7 +115,7 @@ pipeline { } stage('New pending deploy ') { when{ - environment name: 'IS_CRON_TMP', value: 'True' + environment name: 'IS_SCHEDULED', value: 'True' anyOf{ triggeredBy 'BuildUpstreamCause' triggeredBy 'UpstreamCause' @@ -142,7 +142,7 @@ pipeline { } stage('Deploy from job ') { when{ - environment name: 'IS_CRON_TMP', value: 'False'; + environment name: 'IS_SCHEDULED', value: 'False'; expression { env.TRIGGER_CD.toBoolean() } @@ -165,7 +165,7 @@ pipeline { stage('Deploy manually ') { when{ allOf{ - environment name: 'IS_CRON_TMP', value: 'False'; + environment name: 'IS_SCHEDULED', value: 'False'; triggeredBy 'UserIdCause' } }