From 1ca7b3d462b3fbf1ee5b15983a766e34e99529f7 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 15:10:38 -0500 Subject: [PATCH] Parse the previous report and decide what to build. --- Jenkinsfile | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2b5df2f..ccbf07c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -90,6 +90,9 @@ pipeline { GCUBE_RELEASE_NUMBER = "${params.gCube_release_version}" PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" TYPE = "${params.Type}" + JOB_REPORT = "${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" + PREVIOUS_JOB_REPORT = "${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER -1}.csv" + } // see https://jenkins.io/doc/book/pipeline/syntax/#parameters @@ -109,6 +112,10 @@ pipeline { booleanParam(name: 'cleanup_local_repo', defaultValue: true, description: 'Wipe out the local maven repository before the builds?') + + booleanParam(name: 'resume', + defaultValue: false, + description: 'Resume from previous build?') } //see https://jenkins.io/doc/book/pipeline/syntax/#stages @@ -139,9 +146,9 @@ pipeline { echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv #job report - echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv - echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv - echo -e "JobName,Status" >> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv + echo "#Build ${PIPELINE_BUILD_NUMBER}" > $JOB_REPORT + echo "#StartTime ${date}" >> $JOB_REPORT + echo -e "JobName,Status" >> $JOB_REPORT ''' } } @@ -210,13 +217,18 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) { - def gjob = build job: name, propagate: true, wait: true, - parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_settings_file}"], - [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], - [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] - ] - sh "echo -e \\\"${name},${gjob.getResult()}\\\">> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" - println "job results: ${gjob.getResult()}" + if ( (${params.resume}) && (wasSuccess(name)) { + // propagate success + sh "echo -e \\\"${name},SUCCESS\\\">> $JOB_REPORT" + } else { + def gjob = build job: name, propagate: true, wait: true, + parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_settings_file}"], + [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], + [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] + ] + sh "echo -e \\\"${name},${gjob.getResult()}\\\">> $JOB_REPORT" + println "job results: ${gjob.getResult()}" + } } }] } @@ -226,11 +238,14 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { Check if the job was successfully completed in teh given report. */ @NonCPS -boolean wasSuccess(report, job_name) { - "${text}".splitEachLine(',') { columns -> - if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) - return - println "NAME: ${columns[0]} STATUS: ${columns[1]}" +boolean wasSuccess(job_name) { + boolean ret = false + new File("$PREVIOUS_JOB_REPORT").splitEachLine(',') { columns -> + if job_name.equals(columns[0]) && columns[1].equal('SUCCESS') { + ret = true + println "NAME: ${columns[0]} STATUS: ${columns[1]}" + break + } } - false; + ret; } \ No newline at end of file