Continuous Integration in Windows Azure

I wanted to do some continuous integration on a .NET project using Virtual Machines in Windows Azure.

The project is hosted in Bitbucket, and I wanted to try out Teamcity to build it.

Firing up a VM, and installing Teamcity was easy. Configuring Teamcity to build the application wasn’t much harder.

Now we get to the interesting bit. My build machine isn’t very busy. It take a few seconds to build my project (it’s not a very big application) and I don’t spend all day and night working on it, so the machine spends most of it’s time being idle. However, being idle is still racking up a bill.

The solution is to start the machine when it’s needed, and shut it down when not.

Bitbucket (like GitHub) supports service hooks. This is the ability to POST to any URL when a commit is made to the repository, so I created a node.js app which will run on Azure Web Sites, and listen to a service hook. It then starts a Virtual Machine, and shuts it down again, 15 minutes after the last request to start it.

The code is available in this gist: https://gist.github.com/richorama/8052843

You can clone the gist, and install it in your own Web Site using Git and the Azure Command Line Tools:

  git clone https://richorama@gist.github.com/8052843.git vmstartstop

  cd vmstartstop

  azure site create --git

  [edit server.js to set your own values for subscriptionId, hostedService, deploymentId, roleInstance]

  [add a mycert.pem file, following these steps: https://coderead.wordpress.com/2013/08/09/managing-azure-iaas-from-node-js/]

  git add .

  git commit -am "intial commit"

  git push azure master

The app supports two actions, start or stop:

https://xxx.azurewebsites.net/start
https://xxx.azurewebsites.net/stop

 

To install in Bitbucket go to Settings, Hooks and add a ‘POST’:

Untitled

Or in GitHub go to settings, Service Hooks and select WebHook URLs:

Untitled

Conclusion

When you check in to Bitbucket, the VM starts up, builds the project, emails me if there is a problems, and then gets shut down again. Magic.

Advertisements