From 146303c77f23336c0894c71f7977653d7cf0efd4 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 21:28:21 -0400 Subject: [PATCH 01/15] Output ${AGENT_ROOT_FOLDER}/build_commits.txt. --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4495a40..21ff2a6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -120,6 +120,7 @@ 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" + cat "Build #${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.txt ''' } } @@ -242,6 +243,7 @@ pipeline { script { sh ''' mv "${AGENT_ROOT_FOLDER}/settings.${PIPELINE_BUILD_NUMBER}" "${AGENT_ROOT_FOLDER}/settings.xml" + mv ${AGENT_ROOT_FOLDER}/build_commits.txt ${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER} ''' } echo 'The default maven settings have been restored' From 6c6a292cac08ea0027c632721b0a0b62fecdf005 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 22:24:32 -0400 Subject: [PATCH 02/15] Output to CSV. --- Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 21ff2a6..188d630 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -120,7 +120,9 @@ 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" - cat "Build #${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.txt + echo "#Build #${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv + echo -e "URL,Version,Build Number" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + ''' } } @@ -243,7 +245,7 @@ pipeline { script { sh ''' mv "${AGENT_ROOT_FOLDER}/settings.${PIPELINE_BUILD_NUMBER}" "${AGENT_ROOT_FOLDER}/settings.xml" - mv ${AGENT_ROOT_FOLDER}/build_commits.txt ${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER} + mv ${AGENT_ROOT_FOLDER}/build_commits.csv ${AGENT_ROOT_FOLDER}/../build_commits.${PIPELINE_BUILD_NUMBER}.csv ''' } echo 'The default maven settings have been restored' From da41ff292927556e01aac3fb5a8758ab6b1c823f Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 22:37:00 -0400 Subject: [PATCH 03/15] Add start time header to build_commits.csv. --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 188d630..b5d1763 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -120,7 +120,8 @@ 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" - echo "#Build #${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv + echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv + echo "#Start time ${currentBuild.startTimeInMillis}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv echo -e "URL,Version,Build Number" >> ${AGENT_ROOT_FOLDER}/build_commits.csv ''' From 0376d082cf4d71f2fd000167c2590a625547324e Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 22:41:17 -0400 Subject: [PATCH 04/15] Correct start time. --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b5d1763..803d90c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -121,7 +121,8 @@ pipeline { 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 "#Start time ${currentBuild.startTimeInMillis}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + date=`date` + echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv echo -e "URL,Version,Build Number" >> ${AGENT_ROOT_FOLDER}/build_commits.csv ''' From b3fac64bcb956c6f82ec3437f896f882b7d73836 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 22:52:40 -0400 Subject: [PATCH 05/15] Add Component column. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 803d90c..5d3835e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -123,7 +123,7 @@ pipeline { echo "#Build ${PIPELINE_BUILD_NUMBER}" > ${AGENT_ROOT_FOLDER}/build_commits.csv date=`date` echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - echo -e "URL,Version,Build Number" >> ${AGENT_ROOT_FOLDER}/build_commits.csv + echo -e "Component,Version,URL,Build Number" >> ${AGENT_ROOT_FOLDER}/build_commits.csv ''' } From e6a734f40bd8c5f21ddd4151757a3d2a0fef1712 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 22:56:20 -0400 Subject: [PATCH 06/15] Try to email the build commits. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5d3835e..000a210 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -255,7 +255,7 @@ pipeline { } success { echo 'The pipeline worked!' - mail to: 'jenkinsbuilds@d4science.org', + emailext attachmentsPattern: "${AGENT_ROOT_FOLDER}/../build_commits.${PIPELINE_BUILD_NUMBER}.csv", to: 'jenkinsbuilds@d4science.org', subject: "[Jenkins build D4S] build ${currentBuild.fullDisplayName} worked", body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" } From 572d3b1727ec794047ebd160a4dbab56a9a0ab57 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 22:57:59 -0400 Subject: [PATCH 07/15] Add release header. --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 000a210..caf66d7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -121,6 +121,7 @@ pipeline { 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 "Component,Version,URL,Build Number" >> ${AGENT_ROOT_FOLDER}/build_commits.csv From c36ef9e2a48f4f49cc819c95ef607a5136335e30 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 23:01:14 -0400 Subject: [PATCH 08/15] Fix path for build commits. --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index caf66d7..a1234c0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -121,7 +121,7 @@ pipeline { 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 + echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv date=`date` echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv echo -e "Component,Version,URL,Build Number" >> ${AGENT_ROOT_FOLDER}/build_commits.csv @@ -248,7 +248,7 @@ pipeline { script { sh ''' 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 + mv ${AGENT_ROOT_FOLDER}/build_commits.csv ${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER}.csv ''' } echo 'The default maven settings have been restored' @@ -256,7 +256,7 @@ pipeline { } success { echo 'The pipeline worked!' - emailext attachmentsPattern: "${AGENT_ROOT_FOLDER}/../build_commits.${PIPELINE_BUILD_NUMBER}.csv", to: 'jenkinsbuilds@d4science.org', + emailext attachmentsPattern: "${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER}.csv", to: 'jenkinsbuilds@d4science.org', subject: "[Jenkins build D4S] build ${currentBuild.fullDisplayName} worked", body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" } From 1f0de2eaa074404262850c15ce6c5c8f93e6882a Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 21 Oct 2019 23:28:35 -0400 Subject: [PATCH 09/15] Adjust emails. Attach log in case of failures. --- Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a1234c0..395642f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -256,13 +256,15 @@ pipeline { } success { echo 'The pipeline worked!' - emailext attachmentsPattern: "${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER}.csv", to: 'jenkinsbuilds@d4science.org', + emailext attachmentsPattern: "${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER}.csv", + to: 'jenkinsbuilds@d4science.org', subject: "[Jenkins build D4S] build ${currentBuild.fullDisplayName} worked", body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" } failure { echo 'The pipeline has failed' - mail to: 'jenkinsbuilds@d4science.org', + emailext attachLog: true, + to: 'jenkinsbuilds@d4science.org', subject: "[Jenkins build D4S] build ${currentBuild.fullDisplayName} failed", body: "Something is wrong with ${env.BUILD_URL}" } From 591cc0d31a78c12edc1fcb572f8efc6e76cc46da Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 22 Oct 2019 08:33:50 -0400 Subject: [PATCH 10/15] Adjust email attachments. --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 395642f..84b2445 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -249,6 +249,7 @@ pipeline { sh ''' 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 . ''' } echo 'The default maven settings have been restored' @@ -256,7 +257,7 @@ pipeline { } success { echo 'The pipeline worked!' - emailext attachmentsPattern: "${AGENT_ROOT_FOLDER}/build_commits.${PIPELINE_BUILD_NUMBER}.csv", + emailext attachmentsPattern: "**/${PIPELINE_BUILD_NUMBER}.csv", to: 'jenkinsbuilds@d4science.org', subject: "[Jenkins build D4S] build ${currentBuild.fullDisplayName} worked", body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" From f9de2f145e61b9a59c952fe8cefbd8f8a8d0c45f Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 22 Oct 2019 08:56:23 -0400 Subject: [PATCH 11/15] Adjust filename for attachments. Add email ext to README. --- Jenkinsfile | 3 ++- README.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 84b2445..73d3c4f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -250,6 +250,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 */${PIPELINE_BUILD_NUMBER}.csv | echo ''' } echo 'The default maven settings have been restored' @@ -257,7 +258,7 @@ pipeline { } success { echo 'The pipeline worked!' - emailext attachmentsPattern: "**/${PIPELINE_BUILD_NUMBER}.csv", + emailext attachmentsPattern: "**/*.${PIPELINE_BUILD_NUMBER}.csv", to: 'jenkinsbuilds@d4science.org', subject: "[Jenkins build D4S] build ${currentBuild.fullDisplayName} worked", body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" diff --git a/README.md b/README.md index b1ddcea..b329935 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ Jenkins Pipeline script to manage a complete gCube release. * [Pipeline: Maven](https://plugins.jenkins.io/pipeline-maven) * [Pipeline: Basic Steps](https://plugins.jenkins.io/workflow-basic-steps) * [Kubernetes](https://plugins.jenkins.io/kubernetes) (for the YAML parser) -* [NodeLabelParameter](https://plugins.jenkins.io/nodelabelparameter) (The node and label parameter plugin allows to dynamically select the node on which a job should be executed.) +* [NodeLabelParameter](https://plugins.jenkins.io/nodelabelparameter) (to allow to dynamically select the node on which a job should be executed) +* [Email Extension](https://plugins.jenkins.io/email-ext) (to send emails with attachments) * Jenkins configured with a JDK global tool named 'OpenJDK 8' * Jenkins configured with a Maven global tool named 'Maven 3.6.2' * One or more Jenkins agents labeled as 'CD' From 44423acd60cd6e229a418851d4dd9ed45a002ad1 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 22 Oct 2019 09:12:37 -0400 Subject: [PATCH 12/15] Echo the report. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 73d3c4f..cb20ea5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -250,7 +250,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 */${PIPELINE_BUILD_NUMBER}.csv | echo + cat *${PIPELINE_BUILD_NUMBER}.csv | echo ''' } echo 'The default maven settings have been restored' From fedf9bf2c333e0901dc553f909a9b473e3380403 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 22 Oct 2019 15:05:13 -0400 Subject: [PATCH 13/15] Send report separately from build results to the releases mailing list. --- Jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cb20ea5..5900be5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -80,6 +80,7 @@ pipeline { REMOVE_LOCAL_REPO = "${params.cleanup_local_repo}" GCUBE_RELEASE_NUMBER = "${params.gCube_release_version}" PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" + TYPE = "${params.Type}" } // see https://jenkins.io/doc/book/pipeline/syntax/#parameters @@ -250,7 +251,6 @@ 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 *${PIPELINE_BUILD_NUMBER}.csv | echo ''' } echo 'The default maven settings have been restored' @@ -258,10 +258,13 @@ pipeline { } success { echo 'The pipeline worked!' - emailext attachmentsPattern: "**/*.${PIPELINE_BUILD_NUMBER}.csv", - to: 'jenkinsbuilds@d4science.org', + emailext to: 'jenkinsbuilds@d4science.org', subject: "[Jenkins build D4S] build ${currentBuild.fullDisplayName} worked", body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" + emailext attachmentsPattern: "**/*.${PIPELINE_BUILD_NUMBER}.csv", + to: 'jenkinsreleases@d4science.org', + subject: "[Jenkins ${TYPE} report] report for ${currentBuild.fullDisplayName}", + body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" } failure { echo 'The pipeline has failed' From d191329eb76188eb7ec90eb6b75269a28e46096e Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 22 Oct 2019 15:17:31 -0400 Subject: [PATCH 14/15] Adjust subject and body. --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5900be5..eb17b22 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -263,8 +263,8 @@ pipeline { body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" emailext attachmentsPattern: "**/*.${PIPELINE_BUILD_NUMBER}.csv", to: 'jenkinsreleases@d4science.org', - subject: "[Jenkins ${TYPE} report] report for ${currentBuild.fullDisplayName}", - body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" + subject: "${TYPE} report for release ${GCUBE_RELEASE_NUMBER} (build #${PIPELINE_BUILD_NUMBER})", + body: "${currentBuild.fullDisplayName}. Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" } failure { echo 'The pipeline has failed' From d355a673c3f1222ae9a3b361094f02a355098c7e Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Tue, 22 Oct 2019 22:56:48 -0400 Subject: [PATCH 15/15] Add more columns to the report. --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index eb17b22..0a75f05 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -125,8 +125,7 @@ pipeline { echo "#Release ${GCUBE_RELEASE_NUMBER}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv date=`date` echo "#StartTime ${date}" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - echo -e "Component,Version,URL,Build Number" >> ${AGENT_ROOT_FOLDER}/build_commits.csv - + echo -e "GroupID,ArtifactID,Version,SCM URL,Branch,Build Number,Distribution URL,Filename" >> ${AGENT_ROOT_FOLDER}/build_commits.csv ''' } }