From 5d9012680742abaa77622bc1d15ff93ff11790d9 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sat, 7 Dec 2019 18:19:14 -0500 Subject: [PATCH 01/66] Create a job report. --- Jenkinsfile | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4ae5cee..9b2a084 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -130,11 +130,18 @@ pipeline { mv "${AGENT_ROOT_FOLDER}/settings.xml" "${AGENT_ROOT_FOLDER}/settings.${PIPELINE_BUILD_NUMBER}" cp "${AGENT_ROOT_FOLDER}/${MAVEN_SETTINGS_FILE}" "${AGENT_ROOT_FOLDER}/settings.xml" echo "Done with local repository and settings" + + #build report echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv date=`date` echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv 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 ''' } } @@ -203,13 +210,26 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) - build(job: name, + def job = 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']] ]) - } - ] + echo -e "${name},${job.getResult()}" >> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv + }] } } +} +/** + 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 + echo "NAME: columns[0] STATUS: columns[1]" + + } + false; } \ No newline at end of file From 478ac55b21556736dfea0fe779abdfa510da896e Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sat, 7 Dec 2019 22:34:53 -0500 Subject: [PATCH 02/66] Adjust echo command. --- Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9b2a084..d3df7c5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -215,7 +215,9 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - echo -e "${name},${job.getResult()}" >> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv + + sh(script: "echo -e '${name},${job.getResult()}' >> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv") + }] } } @@ -228,8 +230,7 @@ boolean wasSuccess(report, job_name) { "${text}".splitEachLine(',') { columns -> if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) return - echo "NAME: columns[0] STATUS: columns[1]" - + println "NAME: ${columns[0]} STATUS: ${columns[1]}" } false; } \ No newline at end of file From bc02edf4210304c3befea87c134974668c19d98c Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sat, 7 Dec 2019 22:40:14 -0500 Subject: [PATCH 03/66] Adjust echo command, again. --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d3df7c5..840d5ad 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -216,8 +216,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - sh(script: "echo -e '${name},${job.getResult()}' >> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv") - + echo -e '${name},${job.getResult()}' >> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv }] } } From e81bc64dbc44aaa5252c836fc8ca9e8bbbe04b05 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sat, 7 Dec 2019 22:44:36 -0500 Subject: [PATCH 04/66] Adjust echo command, again. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 840d5ad..624f526 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -216,7 +216,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - echo -e '${name},${job.getResult()}' >> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv + sh "echo -e \\\"${name},${job.getResult()}\\\">> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" }] } } From bf5073bebe5e7b14fe3cd85362c3ef8fd50169f6 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sat, 7 Dec 2019 23:07:08 -0500 Subject: [PATCH 05/66] Print job results in the console. --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 624f526..d2ae2d2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -216,7 +216,8 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - sh "echo -e \\\"${name},${job.getResult()}\\\">> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" + //sh "echo -e \\\"${name},${job.getResult()}\\\">> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" + println "job results: ${job.getResult()}" }] } } From 9ec6fae5996d3027f311bbbe23e35505045683f6 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sat, 7 Dec 2019 23:15:57 -0500 Subject: [PATCH 06/66] Rename job var. --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d2ae2d2..80a24a9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -210,14 +210,14 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) - def job = build(job: name, propagate: true, wait: true, + 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},${job.getResult()}\\\">> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" - println "job results: ${job.getResult()}" + //sh "echo -e \\\"${name},${gjob.getResult()}\\\">> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" + println "job results: ${gjob.getResult()}" }] } } From 481a58150fea7c5df26e744fdd7d2e7b0adaa10a Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sat, 7 Dec 2019 23:45:01 -0500 Subject: [PATCH 07/66] Put job obj in scope. --- Jenkinsfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 80a24a9..2b5df2f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -209,15 +209,15 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { if (args.items) { parallel args.items?.collectEntries { name -> ["${name}": { - if (name && !"NONE".equalsIgnoreCase(name)) - def gjob = build(job: name, propagate: true, wait: true, + 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()}" + ] + sh "echo -e \\\"${name},${gjob.getResult()}\\\">> ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" + println "job results: ${gjob.getResult()}" + } }] } } From 1ca7b3d462b3fbf1ee5b15983a766e34e99529f7 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 15:10:38 -0500 Subject: [PATCH 08/66] 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 From 48f8d98fe72d5d28131d1ad16888d1b60e3c30a6 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 15:12:29 -0500 Subject: [PATCH 09/66] Fix syntax. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ccbf07c..25805b2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -217,7 +217,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) { - if ( (${params.resume}) && (wasSuccess(name)) { + if ( (${params.resume}) && (wasSuccess(name)) ) { // propagate success sh "echo -e \\\"${name},SUCCESS\\\">> $JOB_REPORT" } else { From c7b951a4de747a03788b4a1a3ace5bc9e155b91b Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 15:13:53 -0500 Subject: [PATCH 10/66] Fix syntax. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 25805b2..dbc22d4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -241,7 +241,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { boolean wasSuccess(job_name) { boolean ret = false new File("$PREVIOUS_JOB_REPORT").splitEachLine(',') { columns -> - if job_name.equals(columns[0]) && columns[1].equal('SUCCESS') { + if (job_name.equals(columns[0]) && columns[1].equal('SUCCESS')) { ret = true println "NAME: ${columns[0]} STATUS: ${columns[1]}" break From 4326d6613d159c4a7be991a9c27457a13904bee4 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 15:14:52 -0500 Subject: [PATCH 11/66] Remove break statement. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index dbc22d4..1097af3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -244,7 +244,7 @@ boolean wasSuccess(job_name) { if (job_name.equals(columns[0]) && columns[1].equal('SUCCESS')) { ret = true println "NAME: ${columns[0]} STATUS: ${columns[1]}" - break + return } } ret; From 05df0c77f3c6089fcb06db92efc41b1a10e2765e Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 15:55:08 -0500 Subject: [PATCH 12/66] Propagate resume option. --- Jenkinsfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1097af3..1cf8cbe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ import org.yaml.snakeyaml.Yaml def (options, maven_local_repo_path, maven_settings_file, maven_parent_file) = ['', '', '', ''] def agent_root_folder = '/var/lib/jenkins/.m2' def verbose = true - +def resume = ${params.resume} if (params.Type == 'SNAPSHOT-DRY-RUN') { echo "Configure Maven for SNAPSHOT-DRY-RUN artifacts" options = '' @@ -47,6 +47,7 @@ echo "Use local repo at ${maven_local_repo_path}" echo "Release number: ${params.gCube_release_version}" echo "Clean up gcube local artifacts? ${params.cleanup_gcube_artifacts}" echo "Clean up all local artifacts? ${params.cleanup_local_repo}" +echo "Resume from previous build? ${params.resume}" //locate the release file @@ -90,6 +91,7 @@ pipeline { GCUBE_RELEASE_NUMBER = "${params.gCube_release_version}" PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" TYPE = "${params.Type}" + RESUME = "${params.resume}" JOB_REPORT = "${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" PREVIOUS_JOB_REPORT = "${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER -1}.csv" @@ -155,11 +157,12 @@ pipeline { // the maven-parent needs to be built (once) at each execution stage('build maven-parent') { steps { - echo build(job: 'maven-parent', wait: true, + def gjob = build(job: 'maven-parent', wait: true, propagate: true, parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] - ]).result + ]) + sh "echo -e \\\"${name},${gjob.getResult()}\\\">> $JOB_REPORT" echo "Done with maven-parent" } } @@ -169,7 +172,7 @@ pipeline { jsonConfig.gCube_release.Components.each { group_name, component_list -> stage("build ${group_name} components") { buildComponents items: component_list?.collect { "${it.name}" }, - "${maven_settings_file}", "${maven_local_repo_path}" + "${maven_settings_file}", "${maven_local_repo_path}", "${resume}" echo "Done with ${group_name} components" } } @@ -212,12 +215,12 @@ pipeline { } } -def buildComponents(args, maven_settings_file, maven_local_repo_path) { +def buildComponents(args, maven_settings_file, maven_local_repo_path, resume) { if (args.items) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) { - if ( (${params.resume}) && (wasSuccess(name)) ) { + if ( ('true'.equals(${resume})) && (wasSuccess(name)) ) { // propagate success sh "echo -e \\\"${name},SUCCESS\\\">> $JOB_REPORT" } else { From fe1719cce5b9494a9da984c78bc91bd17321147e Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 15:59:50 -0500 Subject: [PATCH 13/66] Add resume also for maven-parent. --- Jenkinsfile | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1cf8cbe..f0e39d4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -157,13 +157,18 @@ pipeline { // the maven-parent needs to be built (once) at each execution stage('build maven-parent') { steps { - def gjob = build(job: 'maven-parent', wait: true, propagate: true, - parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_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" - echo "Done with maven-parent" + if ( ('true'.equals(${resume})) && (wasSuccess('maven-parent')) ) { + // propagate success + sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" + } else { + def gjob = build(job: 'maven-parent', wait: true, propagate: true, + parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], + [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], + [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] + ]) + sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" + echo "Done with maven-parent" + } } } stage('build components') { From 08e55f99b11a375e5660e18b1aaebd65d3e02dbb Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 16:07:06 -0500 Subject: [PATCH 14/66] Wrap maven-parent in a script block. --- Jenkinsfile | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f0e39d4..0746c6a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -157,17 +157,19 @@ pipeline { // the maven-parent needs to be built (once) at each execution stage('build maven-parent') { steps { - if ( ('true'.equals(${resume})) && (wasSuccess('maven-parent')) ) { - // propagate success - sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" - } else { - def gjob = build(job: 'maven-parent', wait: true, propagate: true, - parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], - [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], - [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] - ]) - sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" - echo "Done with maven-parent" + script { + if ( ('true'.equals(${resume})) && (wasSuccess('maven-parent')) ) { + // propagate success + sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" + } else { + def gjob = build(job: 'maven-parent', wait: true, propagate: true, + parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], + [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], + [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] + ]) + sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" + echo "Done with maven-parent" + } } } } From b98633f9bb01edf19c62ea1c3c32b7891aee4f46 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 16:12:11 -0500 Subject: [PATCH 15/66] Fix syntax. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0746c6a..73269fe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -158,7 +158,7 @@ pipeline { stage('build maven-parent') { steps { script { - if ( ('true'.equals(${resume})) && (wasSuccess('maven-parent')) ) { + if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { // propagate success sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" } else { @@ -227,7 +227,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, resume) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) { - if ( ('true'.equals(${resume})) && (wasSuccess(name)) ) { + if ( (resume == 'true') && (wasSuccess(name)) ) { // propagate success sh "echo -e \\\"${name},SUCCESS\\\">> $JOB_REPORT" } else { From e0c766111be9ceeb3232b4df1d22d237d3f3b463 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 23:01:54 -0500 Subject: [PATCH 16/66] Comment echo commands. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 73269fe..7189e75 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -167,7 +167,7 @@ pipeline { [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" + //sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" echo "Done with maven-parent" } } @@ -236,7 +236,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, resume) { [$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" + //sh "echo -e \\\"${name},${gjob.getResult()}\\\">> $JOB_REPORT" println "job results: ${gjob.getResult()}" } } From a6b6c8c7f4b3126f10a03fe9129ca1fbee5f1126 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 23:10:36 -0500 Subject: [PATCH 17/66] Adjust job report path. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7189e75..b096518 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -250,7 +250,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, resume) { @NonCPS boolean wasSuccess(job_name) { boolean ret = false - new File("$PREVIOUS_JOB_REPORT").splitEachLine(',') { columns -> + new File("${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv").splitEachLine(',') { columns -> if (job_name.equals(columns[0]) && columns[1].equal('SUCCESS')) { ret = true println "NAME: ${columns[0]} STATUS: ${columns[1]}" From e8a0a4d3626cd86030f4bf9a8a63b186b414311b Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 23:14:01 -0500 Subject: [PATCH 18/66] Remove code to isolate errors. --- Jenkinsfile | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b096518..697cc51 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -158,10 +158,7 @@ pipeline { stage('build maven-parent') { steps { script { - if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { - // propagate success - sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" - } else { + def gjob = build(job: 'maven-parent', wait: true, propagate: true, parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], @@ -169,7 +166,7 @@ pipeline { ]) //sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" echo "Done with maven-parent" - } + } } } @@ -227,10 +224,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, resume) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) { - if ( (resume == 'true') && (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}"], @@ -238,7 +232,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, resume) { ] //sh "echo -e \\\"${name},${gjob.getResult()}\\\">> $JOB_REPORT" println "job results: ${gjob.getResult()}" - } + } }] } From c5216cebda4eb4098c38b7f6f57f033d5bbce681 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 8 Dec 2019 23:21:40 -0500 Subject: [PATCH 19/66] Fix the env variables. --- Jenkinsfile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 697cc51..3805972 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -92,8 +92,8 @@ pipeline { PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" TYPE = "${params.Type}" RESUME = "${params.resume}" - JOB_REPORT = "${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv" - PREVIOUS_JOB_REPORT = "${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER -1}.csv" + JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + PREVIOUS_JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv" } @@ -158,15 +158,18 @@ pipeline { stage('build maven-parent') { steps { script { - + if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { + // propagate success + sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" + } else { def gjob = build(job: 'maven-parent', wait: true, propagate: true, parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - //sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" + sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" echo "Done with maven-parent" - + } } } } @@ -224,15 +227,18 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, resume) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) { - + if ( (resume == 'true') && (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" + sh "echo -e \\\"${name},${gjob.getResult()}\\\">> $JOB_REPORT" println "job results: ${gjob.getResult()}" - + } } }] } From f19fb497fbabb6a009af78dc2c2c52c9b33db7be Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 15:17:37 -0500 Subject: [PATCH 20/66] Restore jenkins file. --- Jenkinsfile | 80 ++++++++++++----------------------------------------- 1 file changed, 17 insertions(+), 63 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3805972..4ae5cee 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ import org.yaml.snakeyaml.Yaml def (options, maven_local_repo_path, maven_settings_file, maven_parent_file) = ['', '', '', ''] def agent_root_folder = '/var/lib/jenkins/.m2' def verbose = true -def resume = ${params.resume} + if (params.Type == 'SNAPSHOT-DRY-RUN') { echo "Configure Maven for SNAPSHOT-DRY-RUN artifacts" options = '' @@ -47,7 +47,6 @@ echo "Use local repo at ${maven_local_repo_path}" echo "Release number: ${params.gCube_release_version}" echo "Clean up gcube local artifacts? ${params.cleanup_gcube_artifacts}" echo "Clean up all local artifacts? ${params.cleanup_local_repo}" -echo "Resume from previous build? ${params.resume}" //locate the release file @@ -91,10 +90,6 @@ pipeline { GCUBE_RELEASE_NUMBER = "${params.gCube_release_version}" PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" TYPE = "${params.Type}" - RESUME = "${params.resume}" - JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" - PREVIOUS_JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv" - } // see https://jenkins.io/doc/book/pipeline/syntax/#parameters @@ -114,10 +109,6 @@ 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,38 +130,23 @@ pipeline { mv "${AGENT_ROOT_FOLDER}/settings.xml" "${AGENT_ROOT_FOLDER}/settings.${PIPELINE_BUILD_NUMBER}" cp "${AGENT_ROOT_FOLDER}/${MAVEN_SETTINGS_FILE}" "${AGENT_ROOT_FOLDER}/settings.xml" echo "Done with local repository and settings" - - #build report echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv date=`date` echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv 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}" > $JOB_REPORT - echo "#StartTime ${date}" >> $JOB_REPORT - echo -e "JobName,Status" >> $JOB_REPORT ''' } } // the maven-parent needs to be built (once) at each execution stage('build maven-parent') { steps { - script { - if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { - // propagate success - sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" - } else { - def gjob = build(job: 'maven-parent', wait: true, propagate: true, - parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], - [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], - [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] - ]) - sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" - echo "Done with maven-parent" - } - } + echo build(job: 'maven-parent', wait: true, + parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], + [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], + [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] + ]).result + echo "Done with maven-parent" } } stage('build components') { @@ -179,7 +155,7 @@ pipeline { jsonConfig.gCube_release.Components.each { group_name, component_list -> stage("build ${group_name} components") { buildComponents items: component_list?.collect { "${it.name}" }, - "${maven_settings_file}", "${maven_local_repo_path}", "${resume}" + "${maven_settings_file}", "${maven_local_repo_path}" echo "Done with ${group_name} components" } } @@ -222,40 +198,18 @@ pipeline { } } -def buildComponents(args, maven_settings_file, maven_local_repo_path, resume) { +def buildComponents(args, maven_settings_file, maven_local_repo_path) { if (args.items) { parallel args.items?.collectEntries { name -> ["${name}": { - if (name && !"NONE".equalsIgnoreCase(name)) { - if ( (resume == 'true') && (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()}" - } - } - }] + if (name && !"NONE".equalsIgnoreCase(name)) + build(job: name, + 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']] + ]) + } + ] } } -} -/** - Check if the job was successfully completed in teh given report. -*/ -@NonCPS -boolean wasSuccess(job_name) { - boolean ret = false - new File("${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv").splitEachLine(',') { columns -> - if (job_name.equals(columns[0]) && columns[1].equal('SUCCESS')) { - ret = true - println "NAME: ${columns[0]} STATUS: ${columns[1]}" - return - } - } - ret; } \ No newline at end of file From c97451b1a6e8aa45b3af36977995fe2770aaa9cf Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 15:23:03 -0500 Subject: [PATCH 21/66] Restore resume parameter. --- Jenkinsfile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4ae5cee..ef19e55 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ import org.yaml.snakeyaml.Yaml def (options, maven_local_repo_path, maven_settings_file, maven_parent_file) = ['', '', '', ''] def agent_root_folder = '/var/lib/jenkins/.m2' def verbose = true - +def resume = ${params.resume} if (params.Type == 'SNAPSHOT-DRY-RUN') { echo "Configure Maven for SNAPSHOT-DRY-RUN artifacts" options = '' @@ -47,6 +47,7 @@ echo "Use local repo at ${maven_local_repo_path}" echo "Release number: ${params.gCube_release_version}" echo "Clean up gcube local artifacts? ${params.cleanup_gcube_artifacts}" echo "Clean up all local artifacts? ${params.cleanup_local_repo}" +echo "Resume from previous build? ${params.resume}" //locate the release file @@ -90,6 +91,9 @@ pipeline { GCUBE_RELEASE_NUMBER = "${params.gCube_release_version}" PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" TYPE = "${params.Type}" + RESUME = "${params.resume}" + JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + PREVIOUS_JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv" } // see https://jenkins.io/doc/book/pipeline/syntax/#parameters @@ -109,6 +113,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 From 315626848ff483a866c7c6a2c31c8fd49ad6d972 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 15:31:21 -0500 Subject: [PATCH 22/66] Fix resume syntax. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ef19e55..f809241 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ import org.yaml.snakeyaml.Yaml def (options, maven_local_repo_path, maven_settings_file, maven_parent_file) = ['', '', '', ''] def agent_root_folder = '/var/lib/jenkins/.m2' def verbose = true -def resume = ${params.resume} +def resume = params.resume if (params.Type == 'SNAPSHOT-DRY-RUN') { echo "Configure Maven for SNAPSHOT-DRY-RUN artifacts" options = '' From 1de672a7c5e08d83c0abfd589d0970fc3865909b Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 15:42:24 -0500 Subject: [PATCH 23/66] Restore initialize stage. --- Jenkinsfile | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f809241..4301b3b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -124,25 +124,32 @@ pipeline { stage('initialize') { steps { sh ''' - echo "REMOVE_LOCAL_REPO: ${REMOVE_LOCAL_REPO}" - echo "CLEANUP_GCUBE_REPO: ${CLEANUP_GCUBE_REPO}" - if [ "$CLEANUP_GCUBE_REPO" = "true" ]; then - echo "Remove gCube artifacts from local repository" - rm -rf $MAVEN_LOCAL_REPO/org/gcube - fi - if [ "$REMOVE_LOCAL_REPO" = "true" ]; then - echo "Create a fresh local repository" - rm -rf $MAVEN_LOCAL_REPO - mkdir -p $MAVEN_LOCAL_REPO - fi - mv "${AGENT_ROOT_FOLDER}/settings.xml" "${AGENT_ROOT_FOLDER}/settings.${PIPELINE_BUILD_NUMBER}" - cp "${AGENT_ROOT_FOLDER}/${MAVEN_SETTINGS_FILE}" "${AGENT_ROOT_FOLDER}/settings.xml" - echo "Done with local repository and settings" - echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv - echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - date=`date` - echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + echo "REMOVE_LOCAL_REPO: ${REMOVE_LOCAL_REPO}" + echo "CLEANUP_GCUBE_REPO: ${CLEANUP_GCUBE_REPO}" + if [ "$CLEANUP_GCUBE_REPO" = "true" ]; then + echo "Remove gCube artifacts from local repository" + rm -rf $MAVEN_LOCAL_REPO/org/gcube + fi + if [ "$REMOVE_LOCAL_REPO" = "true" ]; then + echo "Create a fresh local repository" + rm -rf $MAVEN_LOCAL_REPO + mkdir -p $MAVEN_LOCAL_REPO + fi + mv "${AGENT_ROOT_FOLDER}/settings.xml" "${AGENT_ROOT_FOLDER}/settings.${PIPELINE_BUILD_NUMBER}" + cp "${AGENT_ROOT_FOLDER}/${MAVEN_SETTINGS_FILE}" "${AGENT_ROOT_FOLDER}/settings.xml" + echo "Done with local repository and settings" + + #build report + echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv + echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + date=`date` + echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + 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}" > $JOB_REPORT + echo "#StartTime ${date}" >> $JOB_REPORT + echo -e "JobName,Status" >> $JOB_REPORT ''' } } From 54b0bb03de9ba0401af288ae1e19362b47f28147 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 15:49:33 -0500 Subject: [PATCH 24/66] Manage job report for maven-parent. --- Jenkinsfile | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4301b3b..b08183f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -156,12 +156,20 @@ pipeline { // the maven-parent needs to be built (once) at each execution stage('build maven-parent') { steps { - echo build(job: 'maven-parent', wait: true, - parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], - [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], - [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] - ]).result - echo "Done with maven-parent" + script { + if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { + // propagate success + sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" + } else { + def gjob = build(job: 'maven-parent', wait: true, propagate: true, + parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], + [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], + [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] + ]) + sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" + echo "Done with maven-parent" + } + } } } stage('build components') { @@ -227,4 +235,20 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { ] } } +} + +/** + Check if the job was successfully completed in teh given report. +*/ +@NonCPS +boolean wasSuccess(job_name) { + boolean ret = false + new File("${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv").splitEachLine(',') { columns -> + if (job_name.equalsIgnoreCase(columns[0]) && columns[1].equalsIgnoreCase('SUCCESS')) { + ret = true + println "NAME: ${columns[0]} STATUS: ${columns[1]}" + return + } + } + ret; } \ No newline at end of file From ed4b6bcef01c03a9e2f69948d4077408dc482a98 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 16:00:42 -0500 Subject: [PATCH 25/66] Wrap code into a stage block. --- Jenkinsfile | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b08183f..21cca11 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -157,17 +157,19 @@ pipeline { stage('build maven-parent') { steps { script { - if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { - // propagate success - sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" - } else { - def gjob = build(job: 'maven-parent', wait: true, propagate: true, - parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], - [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], - [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] - ]) - sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" - echo "Done with maven-parent" + stage('check and build') { + if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { + // propagate success + sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" + } else { + def gjob = build(job: 'maven-parent', wait: true, propagate: true, + parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], + [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], + [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] + ]) + sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" + echo "Done with maven-parent" + } } } } From 9ec18e4bf27f6db76545c0a3abb574a832252756 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 16:02:48 -0500 Subject: [PATCH 26/66] Remove script block. --- Jenkinsfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 21cca11..9f631be 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -156,8 +156,7 @@ pipeline { // the maven-parent needs to be built (once) at each execution stage('build maven-parent') { steps { - script { - stage('check and build') { + if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { // propagate success sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" @@ -170,8 +169,7 @@ pipeline { sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" echo "Done with maven-parent" } - } - } + } } stage('build components') { From f2298fff6308b44695691a287a28bd80fb49ef68 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 16:13:36 -0500 Subject: [PATCH 27/66] Remove stage block. --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9f631be..12f1ebe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -156,7 +156,7 @@ pipeline { // the maven-parent needs to be built (once) at each execution stage('build maven-parent') { steps { - + script { if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { // propagate success sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" @@ -170,6 +170,7 @@ pipeline { echo "Done with maven-parent" } + } } } stage('build components') { From 517153a3ae292641021952e439b054d5b43d92bb Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 16:35:11 -0500 Subject: [PATCH 28/66] Parse job report before the pipeline execution. --- Jenkinsfile | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 12f1ebe..42678ea 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -70,6 +70,12 @@ if (verbose) { jsonConfig.gCube_release.Components.each { println it.key } } +def jobs = parseJobs("${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv") +for (job in jobs) { + println "$job" +} + + pipeline { // see https://jenkins.io/doc/book/pipeline/syntax/#agent @@ -157,7 +163,7 @@ pipeline { stage('build maven-parent') { steps { script { - if ( ("${resume}" == 'true') && (wasSuccess('maven-parent')) ) { + if ( ("${resume}" == 'true') && (jobs['maven-parent'] == 'SUCCESS') ) { // propagate success sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" } else { @@ -242,14 +248,12 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { Check if the job was successfully completed in teh given report. */ @NonCPS -boolean wasSuccess(job_name) { - boolean ret = false - new File("${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv").splitEachLine(',') { columns -> - if (job_name.equalsIgnoreCase(columns[0]) && columns[1].equalsIgnoreCase('SUCCESS')) { - ret = true - println "NAME: ${columns[0]} STATUS: ${columns[1]}" - return - } +def parseJobs(job_file) { + def jobs = [:] + new File(job_file).splitEachLine(',') { columns -> + if (columns[0].startsWith('#') || columns[0].startsWith('GroupID')) + return + jobs["${columns[0]}"] = columns[1] } - ret; + jobs; } \ No newline at end of file From 68826de75976639cbaf6ede9c4db27cfaf18c416 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 16:50:50 -0500 Subject: [PATCH 29/66] Calculate previous job number. --- Jenkinsfile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 42678ea..3b7d541 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -70,12 +70,12 @@ if (verbose) { jsonConfig.gCube_release.Components.each { println it.key } } -def jobs = parseJobs("${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv") +def report_number = env.BUILD_NUMBER -1 +def jobs = parseJobs("${agent_root_folder}/build_jobs.${report_number}.csv") for (job in jobs) { println "$job" } - pipeline { // see https://jenkins.io/doc/book/pipeline/syntax/#agent @@ -250,10 +250,12 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { @NonCPS def parseJobs(job_file) { def jobs = [:] - new File(job_file).splitEachLine(',') { columns -> - if (columns[0].startsWith('#') || columns[0].startsWith('GroupID')) - return - jobs["${columns[0]}"] = columns[1] - } + try { + new File(job_file).splitEachLine(',') { columns -> + if (columns[0].startsWith('#') || columns[0].startsWith('GroupID')) + return + jobs["${columns[0]}"] = columns[1] + } + } catch() {println "Previous job report not available"} jobs; } \ No newline at end of file From 1c504c6c64638d0548164996f5963f7599280d86 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 16:54:48 -0500 Subject: [PATCH 30/66] Catch exception if the report is not available. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3b7d541..66c4211 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -256,6 +256,6 @@ def parseJobs(job_file) { return jobs["${columns[0]}"] = columns[1] } - } catch() {println "Previous job report not available"} + } catch(Exception e) {println "Previous job report not available"} jobs; } \ No newline at end of file From b2324d2fad9320f08d333d913b42f227a24ad7d6 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 21:25:54 -0500 Subject: [PATCH 31/66] Print when the maven-parent is skipped. --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 66c4211..1981d50 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -164,6 +164,7 @@ pipeline { steps { script { if ( ("${resume}" == 'true') && (jobs['maven-parent'] == 'SUCCESS') ) { + echo "Skipping maven-parent" // propagate success sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" } else { From 5c120a3207fd53a456ed735baf9f6f666203146e Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 21:37:23 -0500 Subject: [PATCH 32/66] Skip all the jobs if resume is enabled && success. --- Jenkinsfile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1981d50..d13b3a4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -233,12 +233,20 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path) { if (args.items) { parallel args.items?.collectEntries { name -> ["${name}": { - if (name && !"NONE".equalsIgnoreCase(name)) - build(job: name, + if (name && !"NONE".equalsIgnoreCase(name)) { + if ( ("${resume}" == 'true') && (jobs["${name}"] == 'SUCCESS') ) { + echo "Skipping ${name}" + // propagate success + sh "echo -e \\\"${name},SUCCESS\\\">> $JOB_REPORT" + } else { + build(job: name, 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" + } + } } ] } From 520fc3d31b50a737783bfcbb62f2714b3558b427 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 21:42:10 -0500 Subject: [PATCH 33/66] Jobs as parameter. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d13b3a4..c81b0ca 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -186,7 +186,7 @@ pipeline { jsonConfig.gCube_release.Components.each { group_name, component_list -> stage("build ${group_name} components") { buildComponents items: component_list?.collect { "${it.name}" }, - "${maven_settings_file}", "${maven_local_repo_path}" + "${maven_settings_file}", "${maven_local_repo_path}", jobs echo "Done with ${group_name} components" } } @@ -229,7 +229,7 @@ pipeline { } } -def buildComponents(args, maven_settings_file, maven_local_repo_path) { +def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { if (args.items) { parallel args.items?.collectEntries { name -> ["${name}": { From d04abeab48bd716282413554b4918aaff90b6d38 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 21:47:34 -0500 Subject: [PATCH 34/66] Fix gjob. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c81b0ca..73d1cdf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -239,7 +239,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { // propagate success sh "echo -e \\\"${name},SUCCESS\\\">> $JOB_REPORT" } else { - build(job: name, + def gjob = build(job: name, wait: true, propagate: 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']] @@ -261,7 +261,7 @@ def parseJobs(job_file) { def jobs = [:] try { new File(job_file).splitEachLine(',') { columns -> - if (columns[0].startsWith('#') || columns[0].startsWith('GroupID')) + if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) return jobs["${columns[0]}"] = columns[1] } From 447e8dde0ad8a5c28aba1b7e09afe2b981c2759d Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 22:25:44 -0500 Subject: [PATCH 35/66] Adjust path for previous report file. --- Jenkinsfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 73d1cdf..463cd92 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,10 +71,12 @@ if (verbose) { } def report_number = env.BUILD_NUMBER -1 -def jobs = parseJobs("${agent_root_folder}/build_jobs.${report_number}.csv") -for (job in jobs) { - println "$job" -} +def previous_report_file = "${agent_root_folder}/build_jobs.${report_number}.csv" +echo "Previous report file: ${previous_report_file}" +def jobs = parseJobs(previous_report_file) +for (job in jobs) + println job + pipeline { @@ -99,7 +101,7 @@ pipeline { TYPE = "${params.Type}" RESUME = "${params.resume}" JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" - PREVIOUS_JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER -1}.csv" + PREVIOUS_JOB_REPORT = "${previous_report_file}" } // see https://jenkins.io/doc/book/pipeline/syntax/#parameters @@ -244,7 +246,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { [$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" + sh "echo -e \\\"${name},${gjob.getResult()}\\\" >> $JOB_REPORT" } } } From a720c5ea730aab109ba3bc652ae9c24baf304c9d Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 22:37:46 -0500 Subject: [PATCH 36/66] Resume from a given report number. --- Jenkinsfile | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 463cd92..a5eaf7c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ import org.yaml.snakeyaml.Yaml def (options, maven_local_repo_path, maven_settings_file, maven_parent_file) = ['', '', '', ''] def agent_root_folder = '/var/lib/jenkins/.m2' def verbose = true -def resume = params.resume +def resume = params.resume_from if (params.Type == 'SNAPSHOT-DRY-RUN') { echo "Configure Maven for SNAPSHOT-DRY-RUN artifacts" options = '' @@ -70,12 +70,14 @@ if (verbose) { jsonConfig.gCube_release.Components.each { println it.key } } -def report_number = env.BUILD_NUMBER -1 -def previous_report_file = "${agent_root_folder}/build_jobs.${report_number}.csv" -echo "Previous report file: ${previous_report_file}" -def jobs = parseJobs(previous_report_file) -for (job in jobs) - println job +def jobs = [:] +if (resume_from) { + def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" + echo "Previous report file: ${previous_report_file}" + jobs = parseJobs(previous_report_file) + for (job in jobs) + println job +} pipeline { @@ -122,9 +124,9 @@ pipeline { defaultValue: true, description: 'Wipe out the local maven repository before the builds?') - booleanParam(name: 'resume', - defaultValue: false, - description: 'Resume from previous build?') + string(name: 'resume_from', + defaultValue: '', + description: 'Resume from a previous build identified by the build number.') } //see https://jenkins.io/doc/book/pipeline/syntax/#stages From 539b8aaa33331d2a7d706d29ca3081f603383c2f Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 22:49:42 -0500 Subject: [PATCH 37/66] Set the output job report from the groovy env. --- Jenkinsfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a5eaf7c..5dcafa3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -47,7 +47,7 @@ echo "Use local repo at ${maven_local_repo_path}" echo "Release number: ${params.gCube_release_version}" echo "Clean up gcube local artifacts? ${params.cleanup_gcube_artifacts}" echo "Clean up all local artifacts? ${params.cleanup_local_repo}" -echo "Resume from previous build? ${params.resume}" +echo "Resume from previous build? ${params.resume_from}" //locate the release file @@ -177,7 +177,8 @@ pipeline { [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\">> $JOB_REPORT" + echo "Job report file: ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\" >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" echo "Done with maven-parent" } @@ -248,7 +249,8 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { [$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" + echo "Job report file: ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + sh "echo -e \\\"${name},${gjob.getResult()}\\\" >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" } } } @@ -258,7 +260,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { } /** - Check if the job was successfully completed in teh given report. + Loads the jobs from the given report. */ @NonCPS def parseJobs(job_file) { From 9a4525381af1f461e22dbcd38b3d720937f2abc8 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 23:06:07 -0500 Subject: [PATCH 38/66] Print exception on the job report. --- Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5dcafa3..f2af77f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -271,6 +271,9 @@ def parseJobs(job_file) { return jobs["${columns[0]}"] = columns[1] } - } catch(Exception e) {println "Previous job report not available"} + } catch(Exception e) { + println "Previous job report not available" + e.printStackTrace() + } jobs; } \ No newline at end of file From 5185b384527cb1c325b1669df374cd40f60ebe17 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 23:17:16 -0500 Subject: [PATCH 39/66] Remove catch to see the stack trace. --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f2af77f..11884d1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -265,15 +265,15 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { @NonCPS def parseJobs(job_file) { def jobs = [:] - try { + //try { new File(job_file).splitEachLine(',') { columns -> if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) return jobs["${columns[0]}"] = columns[1] } - } catch(Exception e) { - println "Previous job report not available" - e.printStackTrace() - } + //} catch(Exception e) { + // println "Previous job report not available" + // e.printStackTrace() + //} jobs; } \ No newline at end of file From c4c5057886c4297897c3b60b6c2e78a81e8d575f Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 23:19:00 -0500 Subject: [PATCH 40/66] Re-enable catch to see the stack trace. --- Jenkinsfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 11884d1..ae78dd2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -265,15 +265,14 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { @NonCPS def parseJobs(job_file) { def jobs = [:] - //try { + try { new File(job_file).splitEachLine(',') { columns -> if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) return jobs["${columns[0]}"] = columns[1] } - //} catch(Exception e) { - // println "Previous job report not available" - // e.printStackTrace() - //} + } catch(Exception e) { + println "Previous job report not available" + } jobs; } \ No newline at end of file From 5d202f82e7f33be5fb3922a97efcbe5063dddcf4 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 23:27:22 -0500 Subject: [PATCH 41/66] Fix paths for job report. --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ae78dd2..35549e0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -157,9 +157,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}" > $JOB_REPORT - echo "#StartTime ${date}" >> $JOB_REPORT - echo -e "JobName,Status" >> $JOB_REPORT + echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} + echo "#StartTime ${date}" >> ${JOB_REPORT} + echo -e "JobName,Status" >> ${JOB_REPORT} ''' } } @@ -170,7 +170,7 @@ pipeline { if ( ("${resume}" == 'true') && (jobs['maven-parent'] == 'SUCCESS') ) { echo "Skipping maven-parent" // propagate success - sh "echo -e \\\"maven-parent,SUCCESS\\\">> $JOB_REPORT" + sh "echo -e \\\"maven-parent,SUCCESS\\\">> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" } else { def gjob = build(job: 'maven-parent', wait: true, propagate: true, parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], @@ -242,7 +242,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { if ( ("${resume}" == 'true') && (jobs["${name}"] == 'SUCCESS') ) { echo "Skipping ${name}" // propagate success - sh "echo -e \\\"${name},SUCCESS\\\">> $JOB_REPORT" + sh "echo -e \\\"${name},SUCCESS\\\">> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" } else { def gjob = build(job: name, wait: true, propagate: true, parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_settings_file}"], From 48f2be7f2dff0c0627463f68a89bb7f9a9033564 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 9 Dec 2019 23:28:53 -0500 Subject: [PATCH 42/66] Show the job report. --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 35549e0..344e1ff 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -208,6 +208,7 @@ pipeline { mv "${AGENT_ROOT_FOLDER}/settings.${PIPELINE_BUILD_NUMBER}" "${AGENT_ROOT_FOLDER}/settings.xml" mv ${AGENT_ROOT_FOLDER}/build_commits.csv ${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER}.csv cp ${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER}.csv . + cat ${AGENT_ROOT_FOLDER}/build_jobs.${PIPELINE_BUILD_NUMBER}.csv ''' } echo 'The default maven settings have been restored' From d178e328b1f89f65b1338f7eb31a3387aec4b67e Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 10 Dec 2019 22:52:40 -0500 Subject: [PATCH 43/66] Remove double quotes around the job results. --- Jenkinsfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 344e1ff..8347962 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,8 +75,10 @@ if (resume_from) { def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" echo "Previous report file: ${previous_report_file}" jobs = parseJobs(previous_report_file) - for (job in jobs) - println job + if (verbose) { + for (job in jobs) + println job + } } @@ -157,6 +159,7 @@ pipeline { echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv #job report + cat ${PREVIOUS_JOB_REPORT} echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} echo "#StartTime ${date}" >> ${JOB_REPORT} echo -e "JobName,Status" >> ${JOB_REPORT} @@ -170,7 +173,7 @@ pipeline { if ( ("${resume}" == 'true') && (jobs['maven-parent'] == 'SUCCESS') ) { echo "Skipping maven-parent" // propagate success - sh "echo -e \\\"maven-parent,SUCCESS\\\">> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + sh "echo -e maven-parent,SUCCESS">> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" } else { def gjob = build(job: 'maven-parent', wait: true, propagate: true, parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], @@ -178,7 +181,7 @@ pipeline { [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) echo "Job report file: ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" - sh "echo -e \\\"maven-parent,${gjob.getResult()}\\\" >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + sh "echo -e maven-parent,${gjob.getResult()}" >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" echo "Done with maven-parent" } @@ -243,7 +246,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { if ( ("${resume}" == 'true') && (jobs["${name}"] == 'SUCCESS') ) { echo "Skipping ${name}" // propagate success - sh "echo -e \\\"${name},SUCCESS\\\">> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + sh "echo -e ${name},SUCCESS >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" } else { def gjob = build(job: name, wait: true, propagate: true, parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_settings_file}"], @@ -251,7 +254,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) echo "Job report file: ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" - sh "echo -e \\\"${name},${gjob.getResult()}\\\" >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + sh "echo -e ${name},${gjob.getResult()} >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" } } } From d4534fea88a24bf9265cd197e9754caf48f409bb Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 10 Dec 2019 22:58:19 -0500 Subject: [PATCH 44/66] Fix echo syntax. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8347962..bcf5df0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -173,7 +173,7 @@ pipeline { if ( ("${resume}" == 'true') && (jobs['maven-parent'] == 'SUCCESS') ) { echo "Skipping maven-parent" // propagate success - sh "echo -e maven-parent,SUCCESS">> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + sh "echo -e maven-parent,SUCCESS >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" } else { def gjob = build(job: 'maven-parent', wait: true, propagate: true, parameters: [[$class: 'StringParameterValue', name: 'gcube_settings', value: "${maven_parent_file}"], @@ -181,7 +181,7 @@ pipeline { [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) echo "Job report file: ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" - sh "echo -e maven-parent,${gjob.getResult()}" >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" + sh "echo -e maven-parent,${gjob.getResult()} >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" echo "Done with maven-parent" } From be8f943ab90534c57050bd4b88fd714a80a0cea2 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 10 Dec 2019 23:02:24 -0500 Subject: [PATCH 45/66] Handle cat error. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index bcf5df0..818cf1e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -159,7 +159,7 @@ pipeline { echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv #job report - cat ${PREVIOUS_JOB_REPORT} + cat ${previous_report_file} || echo "${previous_report_file} not available" echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} echo "#StartTime ${date}" >> ${JOB_REPORT} echo -e "JobName,Status" >> ${JOB_REPORT} From f9bec52a7124c76d9664a0d8149756085505a1a1 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 21:27:17 -0500 Subject: [PATCH 46/66] Check job report file earlier. --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 818cf1e..00f38ea 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,6 +74,8 @@ def jobs = [:] if (resume_from) { def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" echo "Previous report file: ${previous_report_file}" + new File("${agent_root_folder}/build_jobs.${resume_from}.csv") + jobs = parseJobs(previous_report_file) if (verbose) { for (job in jobs) @@ -160,6 +162,7 @@ pipeline { #job report cat ${previous_report_file} || echo "${previous_report_file} not available" + ls -lrt ${agent_root_folder}/ echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} echo "#StartTime ${date}" >> ${JOB_REPORT} echo -e "JobName,Status" >> ${JOB_REPORT} From 91010266958668ae8e17a5f3e1e9827da845c499 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 22:21:23 -0500 Subject: [PATCH 47/66] List job reports. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 00f38ea..c468291 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -162,7 +162,7 @@ pipeline { #job report cat ${previous_report_file} || echo "${previous_report_file} not available" - ls -lrt ${agent_root_folder}/ + ls -lrt ${AGENT_ROOT_FOLDER}/ echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} echo "#StartTime ${date}" >> ${JOB_REPORT} echo -e "JobName,Status" >> ${JOB_REPORT} From b45efcb2a53b347821c0b1063489e0f78676a321 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 22:32:53 -0500 Subject: [PATCH 48/66] Print lines. --- Jenkinsfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c468291..a9d7796 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,8 +74,10 @@ def jobs = [:] if (resume_from) { def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" echo "Previous report file: ${previous_report_file}" - new File("${agent_root_folder}/build_jobs.${resume_from}.csv") - + def lines = new File("${agent_root_folder}/build_jobs.${resume_from}.csv").readLines() + lines.each { String line -> + println line + } jobs = parseJobs(previous_report_file) if (verbose) { for (job in jobs) @@ -161,7 +163,7 @@ pipeline { echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv #job report - cat ${previous_report_file} || echo "${previous_report_file} not available" + cat ${PREVIOUS_JOB_REPORT} || echo "${previous_report_file} not available" ls -lrt ${AGENT_ROOT_FOLDER}/ echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} echo "#StartTime ${date}" >> ${JOB_REPORT} From 31c46b8fbd837df1d394a05bd6965eadb9d6c2e3 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 22:47:01 -0500 Subject: [PATCH 49/66] Use readfile to read the job report. --- Jenkinsfile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a9d7796..75ecb3e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,10 +74,6 @@ def jobs = [:] if (resume_from) { def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" echo "Previous report file: ${previous_report_file}" - def lines = new File("${agent_root_folder}/build_jobs.${resume_from}.csv").readLines() - lines.each { String line -> - println line - } jobs = parseJobs(previous_report_file) if (verbose) { for (job in jobs) @@ -163,7 +159,7 @@ pipeline { echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv #job report - cat ${PREVIOUS_JOB_REPORT} || echo "${previous_report_file} not available" + cat ${PREVIOUS_JOB_REPORT} || echo "${PREVIOUS_JOB_REPORT} not available" ls -lrt ${AGENT_ROOT_FOLDER}/ echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} echo "#StartTime ${date}" >> ${JOB_REPORT} @@ -275,7 +271,9 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { def parseJobs(job_file) { def jobs = [:] try { - new File(job_file).splitEachLine(',') { columns -> + def content = readFile file:job_file + println content + content.splitEachLine(',') { columns -> if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) return jobs["${columns[0]}"] = columns[1] From 71aeb703654e5d35227c9fbd8c00f7fc5d83a550 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 22:50:16 -0500 Subject: [PATCH 50/66] Change the scope of the report. --- Jenkinsfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 75ecb3e..f50ec6e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,8 +71,9 @@ if (verbose) { } def jobs = [:] +def previous_report_file = '' if (resume_from) { - def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" + previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" echo "Previous report file: ${previous_report_file}" jobs = parseJobs(previous_report_file) if (verbose) { @@ -270,7 +271,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { @NonCPS def parseJobs(job_file) { def jobs = [:] - try { + //try { def content = readFile file:job_file println content content.splitEachLine(',') { columns -> @@ -278,8 +279,8 @@ def parseJobs(job_file) { return jobs["${columns[0]}"] = columns[1] } - } catch(Exception e) { - println "Previous job report not available" - } + //} catch(Exception e) { + // println "Previous job report not available" + //} jobs; } \ No newline at end of file From 9b8d767526099f2710842b11be8b1a454fa1b4fa Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:08:47 -0500 Subject: [PATCH 51/66] Move readFile to a dedicated stage. --- Jenkinsfile | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f50ec6e..f2fe140 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,16 +71,17 @@ if (verbose) { } def jobs = [:] -def previous_report_file = '' -if (resume_from) { - previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" +def previous_report_content = '' +def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" + +/*if (resume_from) { echo "Previous report file: ${previous_report_file}" jobs = parseJobs(previous_report_file) if (verbose) { for (job in jobs) println job } -} +}*/ pipeline { @@ -134,6 +135,15 @@ pipeline { //see https://jenkins.io/doc/book/pipeline/syntax/#stages stages { + stage('resume') { + steps { + sh 'cat ${PREVIOUS_JOB_REPORT}' + content = readFile ${PREVIOUS_JOB_REPORT} + jobs = parseJobs(content) + for (job in jobs) + println job + } + } stage('initialize') { steps { sh ''' @@ -269,10 +279,9 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { Loads the jobs from the given report. */ @NonCPS -def parseJobs(job_file) { +def parseJobs(content) { def jobs = [:] //try { - def content = readFile file:job_file println content content.splitEachLine(',') { columns -> if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) From 2eae025914116ac153165a3ef14cc35b9f820035 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:10:32 -0500 Subject: [PATCH 52/66] Add missing block. --- Jenkinsfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f2fe140..91fd408 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -137,11 +137,13 @@ pipeline { stages { stage('resume') { steps { - sh 'cat ${PREVIOUS_JOB_REPORT}' - content = readFile ${PREVIOUS_JOB_REPORT} - jobs = parseJobs(content) - for (job in jobs) - println job + script { + sh 'cat ${PREVIOUS_JOB_REPORT}' + content = readFile ${PREVIOUS_JOB_REPORT} + jobs = parseJobs(content) + for (job in jobs) + println job + ] } } stage('initialize') { From f3a0bb0a98d71579e4f7ecc248a61a0b50d862bb Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:10:55 -0500 Subject: [PATCH 53/66] Fix syntax. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 91fd408..a10e4c3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -143,7 +143,7 @@ pipeline { jobs = parseJobs(content) for (job in jobs) println job - ] + } } } stage('initialize') { From dabb399da970e66b41d7c25b9b769dd2e73857b0 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:14:11 -0500 Subject: [PATCH 54/66] Do not use parseJobs. --- Jenkinsfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a10e4c3..3859a00 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -140,9 +140,13 @@ pipeline { script { sh 'cat ${PREVIOUS_JOB_REPORT}' content = readFile ${PREVIOUS_JOB_REPORT} - jobs = parseJobs(content) - for (job in jobs) - println job + content.splitEachLine(',') { columns -> + if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) + return + jobs["${columns[0]}"] = columns[1] + } + for (job in jobs) + println job } } } From 676d975fa79e9ecb1b7680bdb2ac28a5c6eaa52f Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:14:59 -0500 Subject: [PATCH 55/66] Print the file content. --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 3859a00..d431b66 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -140,6 +140,7 @@ pipeline { script { sh 'cat ${PREVIOUS_JOB_REPORT}' content = readFile ${PREVIOUS_JOB_REPORT} + println "CONTENT ${content}" content.splitEachLine(',') { columns -> if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) return From 90c536315edc183a74a826ed07260bd150a42b74 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:24:19 -0500 Subject: [PATCH 56/66] Use groovy var to read the file. --- Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d431b66..8aa4a29 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -139,7 +139,7 @@ pipeline { steps { script { sh 'cat ${PREVIOUS_JOB_REPORT}' - content = readFile ${PREVIOUS_JOB_REPORT} + content = readFile ${previous_report_file} println "CONTENT ${content}" content.splitEachLine(',') { columns -> if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) @@ -177,8 +177,6 @@ pipeline { echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv #job report - cat ${PREVIOUS_JOB_REPORT} || echo "${PREVIOUS_JOB_REPORT} not available" - ls -lrt ${AGENT_ROOT_FOLDER}/ echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} echo "#StartTime ${date}" >> ${JOB_REPORT} echo -e "JobName,Status" >> ${JOB_REPORT} From 68814a50d243ceb5a1108eb6c9fdf466e83048ce Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:28:47 -0500 Subject: [PATCH 57/66] Comment split lines. --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8aa4a29..c624133 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -139,15 +139,16 @@ pipeline { steps { script { sh 'cat ${PREVIOUS_JOB_REPORT}' - content = readFile ${previous_report_file} + content = readFile("${previous_report_file}") println "CONTENT ${content}" - content.splitEachLine(',') { columns -> + /*"${content}".splitEachLine(',') { columns -> if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) return jobs["${columns[0]}"] = columns[1] } for (job in jobs) println job + */ } } } From d300e57f52082e9e92b88d864b2af9fdf1ccd0be Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:41:19 -0500 Subject: [PATCH 58/66] Use NonCPS method to parse the jobs. --- Jenkinsfile | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c624133..7ba21d4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -138,17 +138,12 @@ pipeline { stage('resume') { steps { script { - sh 'cat ${PREVIOUS_JOB_REPORT}' content = readFile("${previous_report_file}") - println "CONTENT ${content}" - /*"${content}".splitEachLine(',') { columns -> - if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) - return - jobs["${columns[0]}"] = columns[1] - } - for (job in jobs) - println job - */ + println "JOB REPORT CONTENT: ${content}" + jobs = parseJobs(content) + for (job in jobs) + println job + } } } @@ -287,15 +282,15 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { @NonCPS def parseJobs(content) { def jobs = [:] - //try { - println content - content.splitEachLine(',') { columns -> - if (columns[0].startsWith('#') || columns[0].startsWith('JobName')) - return + try { + for (String line : content) { + if (!line.startsWith('#') && !line.startsWith('JobName')) { + def columns = line.split(',') jobs["${columns[0]}"] = columns[1] } - //} catch(Exception e) { - // println "Previous job report not available" - //} + } + } catch(Exception e) { + println "Previous job report not available" + } jobs; } \ No newline at end of file From 26de7d4e76acb6eebc0a6cdf58f03325263d51da Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:45:24 -0500 Subject: [PATCH 59/66] Split lines before parsing. --- Jenkinsfile | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7ba21d4..5578105 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,16 +74,6 @@ def jobs = [:] def previous_report_content = '' def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" -/*if (resume_from) { - echo "Previous report file: ${previous_report_file}" - jobs = parseJobs(previous_report_file) - if (verbose) { - for (job in jobs) - println job - } -}*/ - - pipeline { // see https://jenkins.io/doc/book/pipeline/syntax/#agent @@ -283,7 +273,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { def parseJobs(content) { def jobs = [:] try { - for (String line : content) { + for (String line : content.split('\n') { if (!line.startsWith('#') && !line.startsWith('JobName')) { def columns = line.split(',') jobs["${columns[0]}"] = columns[1] From 27bf8aa9414d8e66b661f3b9b961da2828ded5b8 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:46:36 -0500 Subject: [PATCH 60/66] Fix syntax. --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5578105..7234b8a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -272,15 +272,15 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { @NonCPS def parseJobs(content) { def jobs = [:] - try { - for (String line : content.split('\n') { + //try { + for (String line : content.split('\n')) { if (!line.startsWith('#') && !line.startsWith('JobName')) { def columns = line.split(',') jobs["${columns[0]}"] = columns[1] } } - } catch(Exception e) { - println "Previous job report not available" - } + //} catch(Exception e) { + // println "Previous job report not available" + //} jobs; } \ No newline at end of file From fbec8bc5db99c04a63e49d855c20e52c5f36c471 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 11 Dec 2019 23:49:28 -0500 Subject: [PATCH 61/66] Adjust resume condition. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7234b8a..7c490d5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -173,7 +173,7 @@ pipeline { stage('build maven-parent') { steps { script { - if ( ("${resume}" == 'true') && (jobs['maven-parent'] == 'SUCCESS') ) { + if (jobs['maven-parent'] == 'SUCCESS') { echo "Skipping maven-parent" // propagate success sh "echo -e maven-parent,SUCCESS >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" @@ -246,7 +246,7 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { parallel args.items?.collectEntries { name -> ["${name}": { if (name && !"NONE".equalsIgnoreCase(name)) { - if ( ("${resume}" == 'true') && (jobs["${name}"] == 'SUCCESS') ) { + if ( (jobs["${name}"] == 'SUCCESS') ) { echo "Skipping ${name}" // propagate success sh "echo -e ${name},SUCCESS >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" From 9a21b62ed73ec17fe9bb589a00d8106ba9c2c01f Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Thu, 12 Dec 2019 09:02:37 -0500 Subject: [PATCH 62/66] Resume a build olny if resume option is set. --- Jenkinsfile | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7c490d5..4f0d326 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -125,15 +125,14 @@ pipeline { //see https://jenkins.io/doc/book/pipeline/syntax/#stages stages { - stage('resume') { + stage('resume previous build?') { steps { script { - content = readFile("${previous_report_file}") - println "JOB REPORT CONTENT: ${content}" - jobs = parseJobs(content) - for (job in jobs) - println job - + if (resume) { + content = readFile("${previous_report_file}") + println "JOB REPORT CONTENT: ${content}" + jobs = parseJobs(content) + } } } } @@ -272,15 +271,15 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { @NonCPS def parseJobs(content) { def jobs = [:] - //try { + try { for (String line : content.split('\n')) { if (!line.startsWith('#') && !line.startsWith('JobName')) { def columns = line.split(',') jobs["${columns[0]}"] = columns[1] } } - //} catch(Exception e) { - // println "Previous job report not available" - //} + } catch(Exception e) { + println "Previous job report not available or not parsable" + } jobs; } \ No newline at end of file From 0a173b49c6b4dcb28b0523364cfd89450f0cc65d Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Thu, 12 Dec 2019 22:20:29 -0500 Subject: [PATCH 63/66] Append new jobs to the previous job report. --- Jenkinsfile | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4f0d326..12a0be3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -125,18 +125,33 @@ pipeline { //see https://jenkins.io/doc/book/pipeline/syntax/#stages stages { - stage('resume previous build?') { + stage('initialize reports') { steps { script { if (resume) { content = readFile("${previous_report_file}") println "JOB REPORT CONTENT: ${content}" jobs = parseJobs(content) + sh "cp ${PREVIOUS_JOB_REPORT} ${JOB_REPORT}" + } else { + sh "echo #Build ${PIPELINE_BUILD_NUMBER} > ${JOB_REPORT}" + sh "echo #StartTime ${date} >> ${JOB_REPORT}" + sh "echo -e JobName,Status >> ${JOB_REPORT}" } } + + sh ''' + #build report + echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv + echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + date=`date` + echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + + ''' } } - stage('initialize') { + stage('initialize local repository') { steps { sh ''' echo "REMOVE_LOCAL_REPO: ${REMOVE_LOCAL_REPO}" @@ -154,17 +169,6 @@ pipeline { cp "${AGENT_ROOT_FOLDER}/${MAVEN_SETTINGS_FILE}" "${AGENT_ROOT_FOLDER}/settings.xml" echo "Done with local repository and settings" - #build report - echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv - echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - date=`date` - echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - 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}" > ${JOB_REPORT} - echo "#StartTime ${date}" >> ${JOB_REPORT} - echo -e "JobName,Status" >> ${JOB_REPORT} ''' } } From 805862f55db250d3f06622b71255c44686356a46 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Thu, 12 Dec 2019 22:50:53 -0500 Subject: [PATCH 64/66] Append new commits to the previous commit report. --- Jenkinsfile | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 12a0be3..86a6108 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -72,7 +72,9 @@ if (verbose) { def jobs = [:] def previous_report_content = '' -def previous_report_file = "${agent_root_folder}/build_jobs.${resume_from}.csv" +def previous_report_file = "${agent_root_folder}/build_jobs.${resume}.csv" +def previous_commit_file = "${agent_root_folder}/build_commits.${resume}.csv" + pipeline { @@ -98,6 +100,7 @@ pipeline { RESUME = "${params.resume}" JOB_REPORT = "${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" PREVIOUS_JOB_REPORT = "${previous_report_file}" + PREVIOUS_COMMIT_REPORT = "${previous_commit_file}" } // see https://jenkins.io/doc/book/pipeline/syntax/#parameters @@ -132,23 +135,27 @@ pipeline { content = readFile("${previous_report_file}") println "JOB REPORT CONTENT: ${content}" jobs = parseJobs(content) - sh "cp ${PREVIOUS_JOB_REPORT} ${JOB_REPORT}" - } else { - sh "echo #Build ${PIPELINE_BUILD_NUMBER} > ${JOB_REPORT}" - sh "echo #StartTime ${date} >> ${JOB_REPORT}" - sh "echo -e JobName,Status >> ${JOB_REPORT}" + sh "rm ${AGENT_ROOT_FOLDER}/build_commits.csv" + sh "cp ${PREVIOUS_COMMIT_REPORT} ${AGENT_ROOT_FOLDER}/build_commits.csv" } } - sh ''' - #build report - echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv - echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - date=`date` - echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + sh ''' + # job report + echo ""#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} + echo "#StartTime ${date}" >> ${JOB_REPORT} + echo -e "JobName,Status" >> ${JOB_REPORT} - ''' + # create build report if not resumed + if [ ! -f ${AGENT_ROOT_FOLDER}/build_commits.csv ]; then + #build report + echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv + echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + date=`date` + echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + echo -e "GroupID,ArtifactID,Version,SCM URL,Build Number,Distribution URL,Filename,Packaging" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + fi + ''' } } stage('initialize local repository') { @@ -186,7 +193,6 @@ pipeline { [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - echo "Job report file: ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" sh "echo -e maven-parent,${gjob.getResult()} >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" echo "Done with maven-parent" } @@ -259,7 +265,6 @@ def buildComponents(args, maven_settings_file, maven_local_repo_path, jobs) { [$class: 'StringParameterValue', name: 'local_repo', value: "${maven_local_repo_path}"], [$class: 'LabelParameterValue', name: 'exec_label', label: "CD", nodeEligibility: [$class: 'AllNodeEligibility']] ]) - echo "Job report file: ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" sh "echo -e ${name},${gjob.getResult()} >> ${agent_root_folder}/build_jobs.${env.BUILD_NUMBER}.csv" } } From 05fd05954966f2973ae25e571b5868eec6730288 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Thu, 12 Dec 2019 22:53:06 -0500 Subject: [PATCH 65/66] Tolerate that the build report is not available. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 86a6108..918020f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -135,7 +135,7 @@ pipeline { content = readFile("${previous_report_file}") println "JOB REPORT CONTENT: ${content}" jobs = parseJobs(content) - sh "rm ${AGENT_ROOT_FOLDER}/build_commits.csv" + sh "rm ${AGENT_ROOT_FOLDER}/build_commits.csv || true" sh "cp ${PREVIOUS_COMMIT_REPORT} ${AGENT_ROOT_FOLDER}/build_commits.csv" } } From a7822fd12dffee857b500d2fff41a06ceeeb5151 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Thu, 12 Dec 2019 22:56:27 -0500 Subject: [PATCH 66/66] Fix script syntax. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 918020f..46ec417 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -142,7 +142,7 @@ pipeline { sh ''' # job report - echo ""#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} + echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${JOB_REPORT} echo "#StartTime ${date}" >> ${JOB_REPORT} echo -e "JobName,Status" >> ${JOB_REPORT}