Wednesday, June 29, 2011

Hudson - Sonar - Continuous Integration in Minutes

There is a lot of discussion out there about pros and cons of continuous integration (CI) practices. Key advantage is that this sort of approach could be used as an early warning system for issues with your code. Since it is fairly easy to setup, the disadvantages if any are trivial at least in my mind and not worth discussing until you have implemented at least one set of CI tools. Below is a set up that I implemented recently that took me less than an hour.

Versions of software that were used for this exercise include:
·         Maven – 3.0.3
·         Apache Ant – 1.8.2 (the project that I am working on all still use ANT, thus focusing on ant)
·         Apache Tomcat – 6.0.32
·         JDK – 1.6.0_25
·         Hudson – 2.0.1
·         Sonar – 2.8
·         MySQL – 5.5.13
* where possible I used war file option, this way all my key software deployments are in one place and easy to debug when issues arise.

References that I used:
1.       Install My SQL using mysql-5.5.13-wind32.msi
3.       I selected all default options for this installation and chose my admin username and password as admin/admin
4.       Installed apache-tomcat at C: drive as C:\apache-tomcat-6.0.32 and link to JRE/JDK 1.6.0_25
5.       Installed maven at C: drive as C:\apache-maven-3.0.3
6.       Installed ant at C: drive as C:\apache-ant-1.8.2
7.       Installed at C:\My Downloads\sonar and extracted all the files
8.       Update under C:\My Downloads\sonar\sonar-2.8\sonar-2.8\conf folder to link it to MySQL (make sure the url works before you put it here)
a.       sonar.jdbc.url:  jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
b.      sonar.jdbc.driverClassName:                com.mysql.jdbc.Driver
c.       sonar.jdbc.validationQuery:                select 1
9.       Run mysql.exe –u root < C:\My Downloads\sonar\sonar-2.8\sonar-2.8\extras\database\mysql\create_database.sql
10.       Navigate to C:\My Downloads\sonar\sonar-2.8\sonar-2.8\war and run build-war.bat
11.       Copied sonar war file from war folder to the C:\apache-tomcat-6.0.32\webapps directory
12.       Start tomcat and access sonar at http://localhost:8080/sonar
a.       This will also execute DDL and create tables in mysql sonar db
13.       Login and admin/admin and click configuration to configure various settings (checkstyle, google analytics etc…)
15.       Download and rename it as Hudson-2.0.1.war and copy it to C:\apache-tomcat-6.0.32\webapps (if you get a perm gc or other java memory errors) set CATALINA_OPTS=”-Xmx512m”
16.       Before you restart Apache tomcat set the following variables as well:
a.       Set ANT_HOME= C:\apache-ant-1.8.2
b.      Set MAVEN_HOME= C:\apache-maven-3.0.3
c.       set PATH=%ANT_HOME%\bin;%MAVE_HOME%\bin;%PATH%
17.       Restart Apache Tomcat
18.       Login to Hudson at http://localhost:8080/hudson/
19.       Click Manage Hudson and Manage Plugins
21.       Click available sub tab
22.       Scroll drown and select check box against Hudson sonar Plugin and click install at bottom right corner (scroll to the end and down if necessary)
23.       Navigate back to Hudson main page and click manage Hudson
24.       Select configure system
25.       Add JDK, ANT, MAVEN configurations as shown below
27.       Add sub version or cvs source code repository if available (url, username and password and make sure they are saved)
28.       Under sonar installations click “Add Sonar” button and add the configurations as shown below, make sure database url and server url works.

30.       Create new project (with link to SVN, I removed SVN url for privacy purposes here, but this works J )

32.       Add Invoke Ant Build (since the projects don’t use maven yet, but this is still in works at the time of generation of this article)

34.       Click Save
35.       Click Build Now

37.       Click on Build History link that is generated for every build and click on console to monitor the job progress or errors and take corrective actions if any that may be needed.
38.       Once the build is done, the code coverage results will be published to sonar directly at