ci.jpl: Simplify the logic of emailNotification
This patch simplifies the logic of emailNotification to avoid dependency
on input param "success" to verify the job status.
Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I5ca32ad9e4dbd3d61151e5903456cc43cddf3264
diff --git a/jenkins/ci.jpl b/jenkins/ci.jpl
index 7835fd7..fc624ec 100644
--- a/jenkins/ci.jpl
+++ b/jenkins/ci.jpl
@@ -160,30 +160,35 @@
def generateEmailBody(stage, results) {
// Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
- body = "Check console output at ${env.BUILD_URL} \n\n"
-
- body += "Failed Jobs:\n"
+ failed_jobs = ""
results.each { job ->
if (job.value['RESULT'] == 'FAILURE') {
- body += "${job.key} ${job.value['URL']}\n"
+ failed_jobs += "${job.key} ${job.value['URL']}\n"
}
}
+ if (failed_jobs == "") {
+ return ""
+ }
+
+ body = "Check console output at ${env.BUILD_URL} \n\n"
+ body += "Failed Jobs:\n${failed_jobs}"
body += "\nFor detailed ${stage} results please refer to \
${env.BUILD_URL}artifact/${stage}_results.csv \n"
return body
}
-def emailNotification(success, stage, results) {
+def emailNotification(stage, results) {
script {
if (env.EMAIL_NOTIFICATION) {
- if (success == true) {
- print("Skip sending as Success for ${stage}")
+ email_body = generateEmailBody(stage, results)
+ if (email_body == "") {
+ print("Skip sending email notification as no failed jobs for ${stage}")
}
else {
emailext (
subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} fail"),
- body: generateEmailBody(stage, results),
+ body: email_body,
to: "${EMAIL_NOTIFICATION}"
)
}
@@ -358,7 +363,7 @@
build_results_for_summary[build.key] = ['URL': build.value.getAbsoluteUrl(),
'RESULT': build.value.result]
}
- emailNotification(success, 'build', build_results_for_summary)
+ emailNotification('build', build_results_for_summary)
writeCsv(build_results_for_summary, "build_results.csv")
writeHTML(build_results_for_summary, "build_links.html")
}
@@ -416,7 +421,7 @@
archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
archiveArtifacts artifacts: 'cfgs/**', allowEmptyArchive: true
if (all_jobs.size() > 0) {
- emailNotification(success, 'test', test_results)
+ emailNotification('test', test_results)
}
verifyTestStatus(output)
}