Search code examples
buildbot

Customize URL to a failed build in MailNotifier


When my buildbot fails, it is configured to send an email.

Current configuration is:

mailNotify = MailNotifier(fromaddr="****@****.com",
sendToInterestedUsers=True,
extraRecipients=['*****@*****.com', '****@****.com'],
relayhost="mail.****.com",
smtpPort=587,
addLogs = True,
addPatch = True,
useTls=True,
smtpUser="****@****.com",
smtpPassword="****"
mode="failing")

I have a buildmaster setup in my local network, at 192.168.1.11. Because of that, when an email comes, it contains the following information:

Full details are available at:
 http://192.168.1.11:8020/builders/BuilderName/builds/136

Buildbot URL: http://192.168.1.11:8020/

Apart from that, I have a publicly accessible server, by which I can access buildbot, i.e. https://mydomain.com/buildbot/

What I want to get is

Full details are available at:
https://mydomain.com/buildbot/builders/BuilderName/builds/136

Buildbot URL: https://mydomain.com/buildbot/

I'd love NOT to rewrite a whole message formatter, but I couldn't find a way to do that. Is it even possible?


Solution

  • AFAIK the best way is to write your own messageFormatter(). It is not much of a pain. I have done it for my buildbot and it works like a charm.

    If you look into the sources buildbot\status\mail.py there is function called defaultMesage(...). Just override this in your buildbot's configuration and pass it to the MailNotifier constructor ! Most likely you have to change just the line:108

    def myMessageFormatter(mode, name, build, results, master_status)
        # Copy everything from buildbot\status\mail.py:defaultMessage()
    
        # Change this to point to https://mydomain.com/buildbot/
        if master_status.getURLForThing(build):
            text += "Full details are available at:\n %s\n" % master_status.getURLForThing(build)
        text += "\n"