diff --git a/Jenkinsfile.s390x b/Jenkinsfile.s390x index bac2cec75d..32a7d26fe3 100644 --- a/Jenkinsfile.s390x +++ b/Jenkinsfile.s390x @@ -160,7 +160,7 @@ parallel(runITsTasks) } finally { // notify completion stage("Notifications") { - jenkinsNotify() + notify_s390x() } } @@ -171,3 +171,74 @@ def archiveDirs(stageId, archives) { } } } + +def notify_s390x() { + echo "Build result: ${currentBuild.currentResult}" + // determine the message details + def providers + def messageBody + def messageTail = '' + def messageSubject + def sendMail + switch(currentBuild.currentResult) { + case "SUCCESS": + providers = [] + messageSubject = "Build succeeded in Jenkins: ${currentBuild.fullDisplayName}" + messageBody = """See ${currentBuild.absoluteUrl}""" + // only send successfuly builds if the previous build was unsuccessful or incomplete + sendMail = currentBuild.previousBuild == null || !"SUCCESS".equals(currentBuild.previousBuild.result) + break + case "UNSTABLE": + providers = [[$class: 'CulpritsRecipientProvider']] + messageSubject = "Build unstable in Jenkins: ${currentBuild.fullDisplayName}" + messageBody = """See ${currentBuild.absoluteUrl}""" + sendMail = true + messageTail = '\nBuild log:\n${BUILD_LOG}' + break + case "FAILURE": + providers = [[$class: 'CulpritsRecipientProvider']] + messageSubject = "Build failed in Jenkins: ${currentBuild.fullDisplayName}" + messageBody = """See ${currentBuild.absoluteUrl}""" + sendMail = true + messageTail = '\nBuild log:\n${BUILD_LOG}' + break + case "ABORTED": + providers = [[$class: 'CulpritsRecipientProvider']] + messageSubject = "Build aborted in Jenkins: ${currentBuild.fullDisplayName}" + messageBody = """See ${currentBuild.absoluteUrl}""" + sendMail = true + messageTail = '\nBuild log:\n${BUILD_LOG}' + break + default: + echo "Unknown status: ${currentBuild.currentResult}" + // should never happen if we are actually being invoked. + return + } + + // add the changes to the email + def authors = [] + if (currentBuild.changeSets.isEmpty() ) { + messageBody = messageBody + "\n\nNo changes.\n"; + } else { + messageBody = messageBody + "\n\nChanges:\n"; + for (def changeSet in currentBuild.changeSets) { + for (def change in changeSet) { + messageBody = messageBody + "\n* ${change.msg.trim().replaceAll('\n','\n ')}" + authors += change.author.id + } + } + messageBody = messageBody + "\n" + } + println("The authors of changes ${authors.unique()}.") + for (def author in authors) { + if (author.matches('(.*)github(.*)')) sendMail = false + } + + if (authors.isEmpty()) sendMail = false + + if (sendMail) { + messageBody = messageBody + '\n${FAILED_TESTS}\n' + messageTail + println("Sending email ...") + emailext body: messageBody, replyTo: 'rishi@ca.ibm.com', subject: messageSubject, to: 'rishi@ca.ibm.com' + } +}