[users at bb.net] Build failures via XMPP (solution)

Kay Hayen kay.hayen at gmail.com
Wed May 11 10:06:25 UTC 2016


Hello there,

long time ago, I had started to look into getting messages from Buildbot
for "desktop notifications". this. For some weeks already, I am now using
this with good results:

from buildbot.plugins import status

def onStatusPush(self):
    chunk = self.queue.popChunk()
    for part in chunk:
        event_type = part["event"]

        if event_type == "buildFinished":
            builder_name = part["payload"]["build"]["builderName"]
            slave_name = part["payload"]["build"]["slave"]
            build_result = " ".join(part["payload"]["build"]["text"])

            for p in part["payload"]["build"]["properties"]:
                if p[0] == "got_revision":
                    got_revision = p[1]
                    break
            else:
                got_revision = "no revision"

            try:
                logs = part["payload"]["build"]["logs"]
            except Exception:
                logs = [["made up", "No log information found"]]

            urls = []
            for log_name, log_url in logs:
                urls.append(log_url)

            urls = "\n".join(urls)

            if "failed" in build_result:
                message = """
name: %(builder_name)s
slave: %(slave_name)s
build_result: %(build_result)s
rev: %(got_revision)s

%(urls)s
    """ % locals()

                subprocess.check_call(
                    [
                        "/usr/share/doc/python-xmpp/examples/xsend.py",
                        "redacted at test.com",
                        message
                    ]
                )

    self.queueNextServerPush()

sp = status.StatusPush(
    serverPushCb = onStatusPush,
    bufferDelay  = 0.5,
    retryDelay   = 5
)
c['status'].append(sp)

I think this might be useful to others too. As you can see, the bulk of it
is about parsing the data and creating the message to send. The
xsend from python-xmpp Debian package works fine for me, and just
takes a ".xsend" in buildmaster user home directory with content like
this:

JID=buildbot at test.com/buildmaster
PASSWORD=cleartext_password

And that was it. Works great for me. Let me know if you have any
comments or enhancements to this. I am not sure if a chat room
would work as a target, that surely would be nice too. I didn't try
that yet.

If anybody wants to take it from here and integrate into Buildbot,
go ahead, assume public domain for my copyright there.

Yours,
Kay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.buildbot.net/pipermail/users/attachments/20160511/9f631c66/attachment.html>


More information about the users mailing list