23 February, 2015

Hubot, Slack and Azure deployments - Part 2 - Getting TeamCity to Build

In the first post, Hubot, Slack and Azure deployments – Part 1, we looked at how to get Hubot up and running on Heroku and jacked into Slack chat.

In this next post we will look at how to get Hubot to fire off TeamCity builds from our commands in the chat. So it builds on the first or at least that we have a Hubut up and running.

The scripts

To get Hubot to perform stuff it uses scripts called drumroll scripts. There is a scripts folder in your project where you can put your own scripts. There is also a crapload of community scripts that we got npm installed when we ran the yeoman generator in part one (yo hubot). If you haven’t installed them you can do a npm install --save hubot-scripts. These scripts has to be in CoffeeScript or JavaScript.

In our environment at work use TeamCity from JetBrains as Build/CI Server and TeamCity deploys the code to azure (via git push) for us, so I don’t have to mock around the azure api’s just yet.

Browsing the Hubot Script Catalog I found teamcity.coffee which does pretty much what we want.

Cracking up Sublime Text I added it to hubot-sripts.json:


I found out while doing this that “team city.coffee” has an dependency on underscore.js which we need to add manually to get it to work.

$ npm install —save undersocre

Commited that to the repository and went to our TeamCity server and created an account for the bot user. After that we set up some config for Heroku and push it up (change the values below to fit your environment).

$ heroku config:add HUBOT_TEAMCITY_USERNAME=bot_account
$ heroku config:add HUBOT_TEAMCITY_PASSWORD=pwd
$ heroic config:add HUBOT_TEAMCITY_HOSTNAME=http://teamcity-server.cloudapp.net/
$ git push heroku master

Wait for the deploy to roll through and Bob’s you’re uncle! In the chat we can now ask the bot user for “help” and we’ll get a few new commands. Like “tc build start ” and “show me builds”

This is what it looks like for me:
commands in action

Next up

Next up we’ll be looking at how to get TeamCity to talk back to Hubot->Slack to tell us how the build went.

Tags: , , , ,