Meet Bob : conversation-driven development
Many teams here at Canal+ use their own ChatOps software to handle repetitive tasks and/or notifications through their favorite chat app (from IRC to Slack). From Hubot to custom solutions, they vary on user’s affinites with programming languages (Hubot scripts are written in CoffeeScript, Lita’s ones are in Ruby) and chat platform (some bots are not compatible with the XMPP protocol).
The idea of a bot spamming an IRC channel is not new. We (developers) are used to this good old funny Quizz bot hanging around in our chatroom at the end of the day. What’s new here is that theses bots are connected to real-life, developer-oriented stuff : think test tools, deployment orchestrators or nerdy webcomics.
For the last couple of months, I’ve been working on providing my team (the CANAL+ Innovation team) with some cool DevOps tools and practices. Last week, we adopted a new robotic gentleman in the family, which was loosely name Bob*. Let’s introduce him.
The urgent need for automation
Today, major parts of our jobs tend to be automated. Many companies making their digital shift try to make conversation between coworkers easier. Most of the time they begin by trying to reduce the amount of email we send/receive every days (from dozens to hundreds, depending on what your job consist of on a daily basis). Softwares like Slack, Hipchat or Discord are good candidates for this job. People spend less time typing long emails and just “chat” with their colleagues.
At the same time, the DevOps guys are trying to automate the testing and deployment (among other things) of our applications. But this automation comes with a trade-off : you have to learn new tools (with their own CLI or web-UI), new dialects, etc. Why can’t we just use the tool everybody already knows ?
Here come the ChatOps magic thing, bringing your shiny tools into the conversation. You will never have to ask your favorite developer to “Open your browser, go to the [devops_tool] webUI, click here, and here, and on that big green button” again (true story). Let him chat with the tool!
From a developer’s point of view, it allows you to stay focused on the important things : the code and the value it creates for the people (customers?) who use the underlying services. Code-centric companies like Github went “officially” into the ChatOps world five years ago or so and use these little robotic dudes on a daily basis to tackle annoying, repetitive tasks. It’s not too late to offer your team a virtual, smart and (not-so-)polite friend.
A DevOps’ best friend : Err
Err was created by @gbin and maintained by a bunch of cool guys around the world (come and say hello on gitter!). Quoting from the official website, it is “a chatbot, a daemon that connects to your favorite chat service and bring your tools into the conversation.”
Errbot is written in Python. DevOps are (often) native Python speakers. It makes it really easy to port large amount of handcrafted scripts to Errbot “plugins”. The anatomy of a minimal Errbot plugin looks like this snippet :
from errbot import BotPlugin, botcmd class MeetBob(BotPlugin): """Bob is a polite plugin for Errbot""" @botcmd def hello(self, msg, args): """Wish you a good day""" return "Good day, Sir!"
See ? Really simple! Errbot provides you with the @botcmd
decorator for standard messaging functions and a bunch of other cool APIs like a Scheduler for periodic tasks (polling, message broadcasting, …), an embedded Webserver to handle custom webhooks (from Github, Jenkins, …) and much more. For a more complete example, check out the err-meetup plugin I wrote to interact with the meetup.com API, i.e :
me : !meetup next Paris-py-Python-Django-friends BOB : No upcoming events. me : ;-(
Our very own Errbot (“Bob”) help us be more productive by joining the conversation in our chatrooms, listening everything we say and eventually triggering a Python function. You don’t need to bring your geeky terminal here : just ask Bob and he will politely execute your order or answer your question (about life, the universe and everything).
Making working with Jenkins fun again
Working with Jenkins is most of the time a pain in the *** for the average, code-focused, non-Jenkins’-old-fashion-UI-savvy developer. You can’t force people to use your new shiny tool if they don’t want — even if you think it will automate some part of their job, like testing and building their code in the case of Jenkins. Using ChatOps software allows them to, well, “chat” with Jenkins.
There was an old and un-maintained Errbot<->Jenkins plugin, only compatible with Python2. So I decided to fork it and make it usable with the latest version of Python, Errbot and Jenkins, adding some cool features on the way. This was a sort of test-run to see how easy it was to hack a plugin for Errbot. Basically, it uses the great python-jenkins
package available to PyPI to communicate with Jenkins, and the Errbot embedded webserver to handle incoming webhooks. You’ll find the complete source here.
Here is an example of our daily workflow for small-sized projects :
me : Bob, build myProject {'branch': 'feature-mysuperfeature'} BOB : Your job should begin shortly: [link-to-myproject-build] (...) BOB : Build #42 SUCCESS for Job myProject! Yeah! me : thx mate!
And voila! Everybody can chat with Bob, in our chatrooms or in a 1to1 conversation over Slack or IRC. This is just a starting point. We can enable Bob to do many, many more things, using just plain Python scripts, and it sounds terribly funny (to me ;-) ).
Have any idea or comments about Bob ? Please tell us on Twitter
- Errbot : http://errbot.io
- Plugins created by the Errbot community : https://github.com/errbotio/errbot/wiki
- ChatOps at Github : https://www.youtube.com/watch?v=NST3u-GjjFw
- ChatOps everywhere : https://www.reddit.com/r/chatops/
Julien Tanay julien.tanay@canal-plus.com
* I admit it : he takes his name from Bob the Builder. Shame on me.
Originally published at developers.canal-plus.com on February 25, 2016 by Julien Tanay