Sunday, February 19, 2012

Part 1: Continuous Integration (CI) with Jenkins for a application using Play Framework 

Intro

A few months ago I have found Play Framework and I started using it to develop a web project. Before using play I was used with Struts, Spring MVC or other web frameworks and also I was using maven to build and pack my applications.
In a large scale project it is a need to have CI configured and automatic deployment. The CI server I use is the open source server Jenkins. If you don't have Jenkins installed and configured check this link for help.

Install play framework

You need to download Play unzip and add the play location into path. If you know how to add a folder to the path then skip the next lines and check how to install the play plugin for Jenkins.
I did the configuration as root:
  1. Unzip play:
    unzip play-1.2.4.zip /destination
  2. Create symbolic link to play(This will help us at version upgrades):
    ln -s /destination/play-1.2.4 /destination/play
  3. Add play to path:
    vi /etc/profile
    The command above will open the profile file for edit.
    Add the following at the end of the file:
    PLAY_PATH=/destination/play
    export PLAY_PATH
    PATH=$PATH:$PLAY_PATH
    export PATH
  4. Logout so the paths are updated.
There you are, play is installed and added to path; it is ready to use

Install Play plugin for Jenkins

Got to Manage Jenkins -> Manage Plugins - > Available Plugin, check on playframework-plugin and install. Restart webserver or Jenkins server (depending if Jenkins is deployed in a webserver or is started as a service). Or you can install it manually by downloading the Jenkins Play plugin.

Configure Jenkins job

Ok, we have installed Play! Framework and configured in path, we’ve installed the Play Plugin for Jenkins, let’s see how we create a Jenkins job for a play project in a few easy steps:
  1. Click on ‘New Job’ in Jenkins dashboard.
  2. Choose a name for your project then click on ‘Build a free-style software project’.
  3. Configure the Play! Application path.
    Jenkins checks out the code from a repository into a working directory. Usually the working directory will be /root/.jenkins/jobs/MyPlayProject/workspace but I have changed the location because when trying to zip the play module using the play build-module command, for some reason when creating a zip file in a hidden directory nothing is written in it. So because of the above motives I have changed the Job working directory to /jenkinsjobs/MyPlayProject/workspace.
    In the workspace folder you will have:
    workspace
    api
    my-play-project

    Check Play! Application path and fill in the path field wih ‘my-play-project’.
  4. Configure source code management GIT/SVN.
  5. Configure Build. From dropdown ‘Add build Step’ choose Play.
  6. Configure play commands:
    I usually add the following commands when building my play modules:
    deps --sync --clearcache
    auto-test
    build-module
    Check this cheat sheet to test other play commands.
  7. save and you are done.

Coming next...

Next I'll show you how you can configure code analysis with Sonar, how to upload your modules to a Nexus and create a dependency chain for your projects.

Check Part 2: Continuous Integration (CI) with Jenkins for a application using Play Framework.

2 comments:

  1. great post, looking forward for more... BTW, in this excellent book there's also a chapter on jenkins and play http://www.packtpub.com/play-framework-cookbook/book

    ReplyDelete