From 427480c594ebc9f0f90a1ef2f9496a3d48fbda40 Mon Sep 17 00:00:00 2001 From: Tim Flink Date: Fri, 18 Jul 2014 22:26:02 +0000 Subject: [PATCH] adding mail status notifications to taskotron buildmaster --- .../templates/taskotron.master.cfg.j2 | 83 ++++++++++++++++--- 1 file changed, 73 insertions(+), 10 deletions(-) diff --git a/roles/taskotron/buildmaster-configure/templates/taskotron.master.cfg.j2 b/roles/taskotron/buildmaster-configure/templates/taskotron.master.cfg.j2 index 50d80220de..a9e716f91e 100644 --- a/roles/taskotron/buildmaster-configure/templates/taskotron.master.cfg.j2 +++ b/roles/taskotron/buildmaster-configure/templates/taskotron.master.cfg.j2 @@ -212,16 +212,79 @@ c['status'].append(html.WebStatus(http_port=8080, authz=authz_cfg, change_hook_dialects={'base':True})) c['status'].append(html.WebStatus(http_port=8010, authz=authz_cfg)) -#from buildbot.status.mail import MailNotifier -# -#mn = MailNotifier(fromaddr="yagisama@gmail.com", -# sendToInterestedUsers=False, -# extraRecipients=["goat@tirfa.com"], -# useTls=True, relayhost="smtp.gmail.com", smtpPort=587, -# smtpUser="yagisama", smtpPassword="Somehw3r", -# mode='all') -# -#c['status'].append(mn) +from buildbot.status.mail import MailNotifier +from buildbot.status.builder import Results + +import cgi + +# http://docs.buildbot.net/current/manual/cfg-statustargets.html#mailnotifier +def html_message_formatter(mode, name, build, results, master_status): + """Provide a customized message to Buildbot's MailNotifier. + + The last 80 lines of the log are provided as well as the changes + relevant to the build. Message content is formatted as html. + """ + result = Results[results] + + limit_lines = 80 + text = list() + text.append(u'

Build status: %s

' % result.upper()) + text.append(u'') + text.append(u"" % build.getSlavename()) + if master_status.getURLForThing(build): + text.append(u'' + % (master_status.getURLForThing(build), + master_status.getURLForThing(build)) + ) + text.append(u'' % build.getReason()) + text.append(u'
Buildslave for this Build:%s
Complete logs for all build steps:%s
Build Reason:%s
') + text.append(u'
') + + logs = [] + steps = build.getSteps() + for step in steps: + if step.getName() == 'runtask': + logs = step.getLogs() + break + + # logs within a step are in reverse order. Search back until we find stdio + for log in reversed(logs): + if log.getName() == 'stdio': + break + + name = "%s.%s" % (log.getStep().getName(), log.getName()) + content = log.getText().splitlines() # Note: can be VERY LARGE + url = u'%s/steps/%s/logs/%s' % (master_status.getURLForThing(build), + log.getStep().getName(), + log.getName()) + + text.append(u'Detailed log of last build step: %s' + % (url, url)) + text.append(u'
') + text.append(u'

Last %d lines of "%s"

' % (limit_lines, name)) + unilist = list() + for line in content[len(content)-limit_lines:]: + unilist.append(cgi.escape(unicode(line,'utf-8'))) + text.append(u'
')
+        text.extend(unilist)
+        text.append(u'
') + text.append(u'

') + text.append(u'-The Buildbot') + return { + 'body': u"\n".join(text), + 'type': 'html' + } + + +mn = MailNotifier(fromaddr='taskotron@fedoraproject.org', + sendToInterestedUsers=False, + mode=('failing', 'exception', 'warning'), + extraRecipients=['qa-taskotron-admin-members@fedoraproject.org'], + relayhost="bastion.phx2.fedoraproject.org", + messageFormatter=html_message_formatter) + +c['status'].append(mn) + ####### PROJECT IDENTITY