Monday, October 28, 2013

Play2 and TeamCity

Play2 and TeamCity


TeamCity


TeamCity from JetBrains is one of main rivals on Continuous Integration space. 

Study the power of TeamCity at


Ot try it live


TeamCity doesn't have SBT or Play2 support out of box, but this is more of a fact than real limitation. As you need to accept that fact you are faced with several options for building your app with TeamCity.

Build with Maven 


You could take layered approach, and add Pom file to your project and control builds with 3rd party Maven plugin. This approach means that you can use existing maven infrastructure and tasks. On the other hand, 3r party maven plugin is extra component which is out of your control and might not be supported after a while.

I haven't tried Maven-Play2-plugin, but it looks like having quite a set of functions.


Build with SBT


Play2's command line tools function as lightweight wrapper over SBT. So, installing SBT to your TeamCity agents and getting build done with SBT looks like sensible approach. 

Again, I can just guess how well this can work, example with Bamboo is here.


Build with Play shell


You can also get Play2 directly installed to TeamCity agents and use command line tools just like you'd do in your local environment

Installing Play to build agent is simple. 
  1. Get Play2 2.2 as Classic distribution zip from http://www.playframework.com/download
  2. Extract to preferred location at your TeamCity agent
  3. Add env.playframework.dir=<extracted-to-dir-name> to <agent home>/conf/buildAgent.properties

Installation brings %env.playframework.dir% environment variable visible to your configurations, and additionally TeamCity manages to restrict build steps only to agents which have Play installed and %env.playframework.dir% defined.

Kicking in play build from command line is simple. 
  • %env.playframework.dir%/play -Dbuild.number=%build.counter% clean dist

Build number is defined using %build.counter% property, which is passed to SBT thru build.number property.

Version numbered build results can be produced easily. Play2's command line parameters can be passed thru SBT to be used in build.sbt. Properties like build.number are read at build.sbt using sys.props. This way version number can be set easily using one-liner.


  • // usage: play -Dbuild.number=123 dist
  • version      := "1.0"+"."+sys.props("build.number")

Here's example of using System.getProperty ("..") which is same as sys.props in build.sbt.

http://www.scala-sbt.org/release/docs/Examples/Quick-Configuration-Examples.html

Build Parameters usage can be checked from TeamCity's documentation


Further steps


No tests? Try "play clean test dist". If needed components could be also published to Nexus. Try "play clean test dist publish", but don't forget publishTo and credentials definitions from build.sbt.  Want your app to be installed directly as part of nightly build. Well.. Here you have more options, since now we can go to direction of AWS, Heroku, Cloudbees or your own dedicated servers.