extract deployPendingJobs method from DeployFromSystem stage

This commit is contained in:
Roberto Cirillo 2022-10-05 09:59:20 +02:00
parent 0735ed9eda
commit 15b75dea9d
1 changed files with 35 additions and 28 deletions

63
Jenkinsfile vendored
View File

@ -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}"
}
}