From 517fbb40f0e522533558baaa92667692333c2910 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 09:54:08 +0100 Subject: [PATCH 01/10] add send mail as post action --- Jenkinsfile | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 3a6485f..f7605c8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,6 +10,14 @@ pipeline { agent { label 'CD' } + + environment { + AGENT_ROOT_FOLDER = "${agent_root_folder}" + PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" + WALKER_NOTES = "${agent_root_folder}/walker_notes.${pipeline_build_number}.md" + } + + parameters { string(name: 'jenkins_project', defaultValue: '', @@ -69,6 +77,34 @@ pipeline { } } } + // post-build actions + post { + always { + script { + sh ''' + cp $WALKER_NOTES ./walker_notes.${PIPELINE_BUILD_NUMBER}.md + cat ./$WALKER_NOTES + ''' + } + } + success { + echo 'The dependencies walker pipeline worked!' + emailext to: 'jenkinsbuilds@d4science.org', + subject: "[Jenkins WalkerPipeline D4S] build ${currentBuild.fullDisplayName} worked", + body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" + emailext attachmentsPattern: "**/walker_notes.${PIPELINE_BUILD_NUMBER}.md", + to: 'jenkinsreleases@d4science.org', + subject: "Walker Dependencies for gCube component ${inputProject} (build #${PIPELINE_BUILD_NUMBER})", + body: "Release notes extracted from the CHANGELOG.md(s) of the released components. See ${env.BUILD_URL}" + } + failure { + echo 'The dependencies walker pipeline has failed' + emailext attachLog: true, + to: 'jenkinsbuilds@d4science.org', + subject: "[JenkinsDependenciesWalker D4S] build ${currentBuild.fullDisplayName} failed", + body: "Something is wrong with ${env.BUILD_URL}" + } + } } // look for modules that use this artifact @@ -145,6 +181,42 @@ def printReport(report) { } println text } + +// print the final report +def saveReport(report) { + def text = '' + def indent = '\t' + text += "Dependency Report for ${report['project']}" + text += "\n\n" + text += "|--Project Maven Modules\n" + report['downstream_modules'].each { depth, artifacts -> + artifacts.each { name, data -> + text += "${indent}|--Module: ${name}\n" + text += "${indent * 2}|--Deepest Dependency Level: ${depth}\n" + text += "${indent * 2}|--Used by (Maven Modules)\n" + data['dependencies'].each { d -> + text += "${indent * 3}|--${d}" + text += "\n" + } + text += "${indent * 2}|--Referred by (Jenkins Projects)\n" + data['projects'].each { p -> + text += "${indent * 3}|--${p}" + text += "\n" + } + } + } + + text += "\n\n" + text += "|--All Downstream Projects\n" + report['downstream_projects'].unique().sort() + report['downstream_projects'].each { p -> + text += "${indent}|--${p}" + text += "\n" + } + text > WALKER_NOTES +} + + // debug job def printJob(job) { println("fullname ${job.fullName}") -- 2.17.1 From bd23fde2d19f72d84241ca69b2f55afb3d6925e7 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 10:39:18 +0100 Subject: [PATCH 02/10] define agent_root_folder variable, add new method appendNotes --- Jenkinsfile | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f7605c8..8164eba 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,11 @@ +def agent_root_folder = '/var/lib/jenkins/.m2' def projects2artifacts = [:] def artifacts2projects = [:] def modules2deps = [:] def alreadyInTheTree = [] def inputProject = params.jenkins_project.trim() def report = [:] + report['project'] = inputProject pipeline { @@ -14,7 +16,7 @@ pipeline { environment { AGENT_ROOT_FOLDER = "${agent_root_folder}" PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" - WALKER_NOTES = "${agent_root_folder}/walker_notes.${pipeline_build_number}.md" + WALKER_NOTES = "${agent_root_folder}/walker_notes.${inputProject}.md" } @@ -83,7 +85,7 @@ pipeline { script { sh ''' cp $WALKER_NOTES ./walker_notes.${PIPELINE_BUILD_NUMBER}.md - cat ./$WALKER_NOTES + cat ./walker_notes.${PIPELINE_BUILD_NUMBER}.md ''' } } @@ -180,43 +182,16 @@ def printReport(report) { text += "\n" } println text + appendNotes(text) + } -// print the final report -def saveReport(report) { - def text = '' - def indent = '\t' - text += "Dependency Report for ${report['project']}" - text += "\n\n" - text += "|--Project Maven Modules\n" - report['downstream_modules'].each { depth, artifacts -> - artifacts.each { name, data -> - text += "${indent}|--Module: ${name}\n" - text += "${indent * 2}|--Deepest Dependency Level: ${depth}\n" - text += "${indent * 2}|--Used by (Maven Modules)\n" - data['dependencies'].each { d -> - text += "${indent * 3}|--${d}" - text += "\n" - } - text += "${indent * 2}|--Referred by (Jenkins Projects)\n" - data['projects'].each { p -> - text += "${indent * 3}|--${p}" - text += "\n" - } - } - } - - text += "\n\n" - text += "|--All Downstream Projects\n" - report['downstream_projects'].unique().sort() - report['downstream_projects'].each { p -> - text += "${indent}|--${p}" - text += "\n" - } - text > WALKER_NOTES +def appendNotes(report) { + sh(""" + echo "${report}" >> $WALKER_NOTES + """) } - // debug job def printJob(job) { println("fullname ${job.fullName}") -- 2.17.1 From 5d67b4355eb30b3d41cc26febca3ea59f55842ea Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 12:27:58 +0100 Subject: [PATCH 03/10] fixed email body and subject; try to enhance the attached file --- Jenkinsfile | 60 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8164eba..142a269 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,6 +75,7 @@ pipeline { steps { script { printReport(report) + saveReport(report) } } } @@ -96,14 +97,14 @@ pipeline { body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" emailext attachmentsPattern: "**/walker_notes.${PIPELINE_BUILD_NUMBER}.md", to: 'jenkinsreleases@d4science.org', - subject: "Walker Dependencies for gCube component ${inputProject} (build #${PIPELINE_BUILD_NUMBER})", - body: "Release notes extracted from the CHANGELOG.md(s) of the released components. See ${env.BUILD_URL}" + subject: "Dependency Report for gCube component ${inputProject} (build #${PIPELINE_BUILD_NUMBER})", + body: "Downstream dependencies of ${inputProject}. See ${env.BUILD_URL}" } failure { echo 'The dependencies walker pipeline has failed' emailext attachLog: true, to: 'jenkinsbuilds@d4science.org', - subject: "[JenkinsDependenciesWalker D4S] build ${currentBuild.fullDisplayName} failed", + subject: "[JenkinsDependenciesWalker D4S] build ${currentBuild.fullDisplayName} failed for component ${inputProject}", body: "Something is wrong with ${env.BUILD_URL}" } } @@ -182,16 +183,59 @@ def printReport(report) { text += "\n" } println text - appendNotes(text) } -def appendNotes(report) { - sh(""" - echo "${report}" >> $WALKER_NOTES - """) +// print the final report +def saveReport(report) { + def text = '' + def indent = '\t' + sh(""" + echo "Dependency Report for ${report['project']}" > $WALKER_NOTES + echo "\n\n" >> $WALKER_NOTES + echo "|--Project Maven Modules " >> $WALKER_NOTES + """) + report['downstream_modules'].each { depth, artifacts -> + artifacts.each { name, data -> + sh(""" + echo "${indent}|--Module: ${name}\n" >> $WALKER_NOTES + echo "${indent * 2}|--Deepest Dependency Level: ${depth}\n" >> $WALKER_NOTES + echo "${indent * 2}|--Used by (Maven Modules)\n" >> $WALKER_NOTES + """) + data['dependencies'].each { d -> + sh(""" + echo "${indent * 3}|--${d}" >> $WALKER_NOTES + echo "\n" >> $WALKER_NOTES + """) + } + sh(""" + echo "${indent * 2}|--Referred by (Jenkins Projects)\n" >> $WALKER_NOTES + """) + data['projects'].each { p -> + sh(""" + echo "${indent * 3}|--${p}" >> $WALKER_NOTES + echo "\n" >> $WALKER_NOTES + """) + } + } + } + sh(""" + echo "\n\n" >> $WALKER_NOTES + echo "|--All Downstream Projects\n" >> $WALKER_NOTES + """) + report['downstream_projects'].unique().sort() + report['downstream_projects'].each { p -> + sh(""" + echo "${indent}|--${p}" >> $WALKER_NOTES + echo "\n" >> $WALKER_NOTES + """) + } + } + + + // debug job def printJob(job) { println("fullname ${job.fullName}") -- 2.17.1 From 423220f3296d6c07bbc67686b05f397be61a1c23 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 14:52:03 +0100 Subject: [PATCH 04/10] fixing attached file --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 142a269..cefe43e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,7 +75,7 @@ pipeline { steps { script { printReport(report) - saveReport(report) +// saveReport(report) } } } @@ -183,6 +183,7 @@ def printReport(report) { text += "\n" } println text + sh printf "%s" $text > $WALKER_NOTES } -- 2.17.1 From 84100a10be6a1569eb3e8c1e56a315543780c223 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 14:58:53 +0100 Subject: [PATCH 05/10] fixing attached file --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index cefe43e..59d6833 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -183,7 +183,9 @@ def printReport(report) { text += "\n" } println text - sh printf "%s" $text > $WALKER_NOTES + sh(""" + printf "%s" $text > $WALKER_NOTES + """) } -- 2.17.1 From 15a482bd26eca0ba66ce5660ce3456ebbe9afc31 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 15:56:38 +0100 Subject: [PATCH 06/10] restored old method appendNotes --- Jenkinsfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 59d6833..0e57fd3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -183,12 +183,16 @@ def printReport(report) { text += "\n" } println text - sh(""" - printf "%s" $text > $WALKER_NOTES - """) + appendNotes(text) } +def appendNotes(report) { + sh(""" + echo -e "${report}" > $WALKER_NOTES + """) +} + // print the final report def saveReport(report) { def text = '' -- 2.17.1 From eebdae552913388cfab4b9a848b62178fc7ed096 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 16:10:09 +0100 Subject: [PATCH 07/10] Trying to execute a bash command --- Jenkinsfile | 52 +--------------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0e57fd3..68c6777 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -188,61 +188,11 @@ def printReport(report) { } def appendNotes(report) { - sh(""" + sh("""#!/bin/bash echo -e "${report}" > $WALKER_NOTES """) } -// print the final report -def saveReport(report) { - def text = '' - def indent = '\t' - sh(""" - echo "Dependency Report for ${report['project']}" > $WALKER_NOTES - echo "\n\n" >> $WALKER_NOTES - echo "|--Project Maven Modules " >> $WALKER_NOTES - """) - report['downstream_modules'].each { depth, artifacts -> - artifacts.each { name, data -> - sh(""" - echo "${indent}|--Module: ${name}\n" >> $WALKER_NOTES - echo "${indent * 2}|--Deepest Dependency Level: ${depth}\n" >> $WALKER_NOTES - echo "${indent * 2}|--Used by (Maven Modules)\n" >> $WALKER_NOTES - """) - data['dependencies'].each { d -> - sh(""" - echo "${indent * 3}|--${d}" >> $WALKER_NOTES - echo "\n" >> $WALKER_NOTES - """) - } - sh(""" - echo "${indent * 2}|--Referred by (Jenkins Projects)\n" >> $WALKER_NOTES - """) - data['projects'].each { p -> - sh(""" - echo "${indent * 3}|--${p}" >> $WALKER_NOTES - echo "\n" >> $WALKER_NOTES - """) - } - } - } - sh(""" - echo "\n\n" >> $WALKER_NOTES - echo "|--All Downstream Projects\n" >> $WALKER_NOTES - """) - report['downstream_projects'].unique().sort() - report['downstream_projects'].each { p -> - sh(""" - echo "${indent}|--${p}" >> $WALKER_NOTES - echo "\n" >> $WALKER_NOTES - """) - } - -} - - - - // debug job def printJob(job) { println("fullname ${job.fullName}") -- 2.17.1 From bfb77ff0240f12c1721519c518939e5dfa04fb4a Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 16:13:02 +0100 Subject: [PATCH 08/10] remove a duplicate cat command --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 68c6777..5437903 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -86,7 +86,6 @@ pipeline { script { sh ''' cp $WALKER_NOTES ./walker_notes.${PIPELINE_BUILD_NUMBER}.md - cat ./walker_notes.${PIPELINE_BUILD_NUMBER}.md ''' } } -- 2.17.1 From 0267459b51ab63f8fb98c079002b5bbaf7b4cd0d Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 16:42:21 +0100 Subject: [PATCH 09/10] clean code --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5437903..a2e9980 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,7 +75,6 @@ pipeline { steps { script { printReport(report) -// saveReport(report) } } } -- 2.17.1 From 893632abfde223fda002b05dbbd1ed06bbf68218 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Thu, 18 Nov 2021 16:10:53 +0100 Subject: [PATCH 10/10] change walkernotes filename --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a2e9980..62366e4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { environment { AGENT_ROOT_FOLDER = "${agent_root_folder}" PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}" - WALKER_NOTES = "${agent_root_folder}/walker_notes.${inputProject}.md" + WALKER_NOTES = "${agent_root_folder}/walker_notes.${PIPELINE_BUILD_NUMBER}.txt" } -- 2.17.1