From 517fbb40f0e522533558baaa92667692333c2910 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 9 Nov 2021 09:54:08 +0100 Subject: [PATCH] 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}")