Академический Документы
Профессиональный Документы
Культура Документы
CONTENTS INCLUDE:
n n
About Continuous Integration Configuring the Machine Installing the CI Server Configuring a Hudson Job Running Tests Tools and more...
Continuous Integration:
Servers and Tools
By Paul M. Duvall
Antipatterns: Requiring developer to define and configure environment variables. Requiring developer to install numerous tools in order for the build/deployment to work.
Relevant Patterns
www.dzone.com
The patterns below are from the CI patterns and anti-patterns Refcard (#84) that are relevant to ci servers and tools and are covered in this Refcard.
Pattern Repository Automated Build Minimal Dependencies Label Build Continuous Feedback Description Commit all files to a version-control repository Automate all activities to build software from source without manual configuration Reduce pre-installed tool dependencies to the bare minimum Label the build with unique name Send automated feedback from CI server to development team Separate build scripts from the IDE Run builds on a separate dedicated machine Run automated code analysis to find common problems Use thresholds to notify team members of code aberrations Securely interface with multiple machines without typing a command Files are shared by authorized team members only Write an automated test for each unique path
Add environment information to the .bash_profile file. Examples are shown below.
ANT_HOME=/usr/local/ant-1.7.0 JAVA_HOME=/usr/jdk1.5.0_10/ HUDSON_HOME=$HOME/hudson_data export ANT_HOME JAVA_HOME HUDSON_HOME export PATH=$ANT_HOME/bin:$JAVA_HOME/bin:$PATH
Save the profile to the system by sourcing the profile as shown below.
. .bash_profile
Independent Build Dedicated Machine Continuous Inspection Build Threshold Headless Execution Protected Configuration Automated Tests
www.dzone.com
Build-tool integration
Install MySQL using yum as shown here. If you are using another flavor of Linux that doesnt support yum, you can use rpm. Or, if youre using Windows, you can download the MySQL installation from http://dev.mysql.com/downloads/ and ensure MySQL is available in your system path.
yum -y install mysql mysql-server
In choosing a CI server, you need to consider which build tools you already use or will be using. For Java programming, there are a couple of clear favorites, Ant and Maven, and most all CI tools support them. If your build system isnt either Ant or Maven, does the CI tool support the ability to run a program from the command line? Consider the old adage, If a tree falls in the forest, does anyone hear it? If a build fails, does anyone hear about it? If no one does, whats the purpose of having a CI tool? All CI tools offer some notification mechanism, but which one will work best for you? E-mail? Instant messenger? RSS? Some development teams like to track builds by giving them unique labels so they can refer to a particular build instance at a later date. If this is important to you, be aware that only some CI servers provide this capability. In some cases, after you build one project, you may need to build another dependent project. Certain CI servers support this feature and some dont. How easy is it to extend the current functionality of the tool? Are there plug-ins that allow for simple extension or is it always a code change?
Install Version-Control System Client Install Subversion client software using yum.
Ease of extensibility yum -y install subversion
Install Tomcat Web Container Download Tomcat by visiting Apache Tomcats download site at: http://tomcat.apache.org/download-60.cgi Save the zip file to the machine where Tomcat will be hosted (e.g. apache-tomcat-6.0.20.zip). Go to the command prompt on the machine and type:
unzip apache-tomcat-6.0.20.zip
One CI server that satisfies these criteria well is Hudson, which will be the focus here. Below you will learn how to download, install, configure Hudson, and configure a Hudson job with CI patterns in mind.
Download Hudson
Hudson is free and openly available at hudson-ci.org. Hudson supports numerous version-control systems, including Subversion (see Repository Pattern in Refcard #84). http://hudson-ci.org/ Download the latest from the website to your machine where Hudson will be hosted. An example is shown below: http://hudson-ci.org/latest/hudson.war
Install Hudson
To install Hudson you will need Java version 1.5 or higher and the Hudson installation file, which is a Java EE Web archive (WAR) file. Typically, you can use a web container, such as Tomcat, and deploy the hudson.war file to the web container. Copy the Hudson.war to Tomcat.
cd ~/hudson/application/webapps/apache-tomcat-6.0.20/webapps
Verify the Hudson CI server is running by launching a web browser and typing: http://localhost:8080/hudson The Hudson server dashboard should be displayed and look similar to the following figure.
www.dzone.com
these build scripts will be executed by a CI system so that software is built at every repository change. Antipatterns: Automated Build relies on IDE settings. Build cannot run from the command line. Protected Configuration Pattern: Using the repository, files are shared by authorized team members only.
Antipatterns: Files are managed on team members machines or stored on shared drives accessible by authorized team members. Continuous Inspection Pattern: Run automated code analysis to find common problems. Have these tools run as part of continuous integration or periodic builds. Antipatterns: Long, manual code reviews or no code reviews.
www.dzone.com
To configure Sonar for a particular job, select a specific Hudson job and then select Configure. From the Post-build Actions section on this page, you will see a Sonar checkbox. Select this checkbox and click the Save button. Typically, you will also need to configure other project-specific options as well. This is illustrated in the screenshot below.
Continuous Inspection
The Continuous Inspection pattern is an approach to running automated code analysis as part of a build in order to find code quality problems. Continuous Inspection can help reduce the time spent in Long, manual code review sessions. While there are numerous tools you can use to implement this pattern, this example shows a tool called Sonar, which collects the information from several code quality analysis tools into comprehensive graphs and reports. Using Sonar Sonar provides code quality reports and graphs using several of the widely used open source static analysis tools on the market. The benefit is that Sonar aggregates the data and displays it as information in an easy-to-understand way. Using Sonar is quite simple in Hudson by downloading Hudsons Sonar Plugin. Add the Sonar plugin to Hudson From the main Hudson dashboard, Select the Manage Hudson link, then Manage Plugins. From Manage Plugins, select the Available tab. From the numerous plugins, select the Hudson Sonar Plugin checkbox and select the Install button. Restart the Tomcat container Go back to the Manage Hudson link and select the Prepare for Shutdown option. This prevents any other jobs from running while you restart the server. Because the Tomcat server is hosting the Hudson CI application, you will access the host where Tomcat is installed and go to the Tomcat bin directory.
cd ~/hudson/application/webapps/apache-tomcat-6.0.20/bin ./shutdown.sh ./startup.sh
RUNNING TESTS
Automated tests Pattern: Write an automated test for each unique path. Antipatterns: Not running tests, no regression tests, manual testing Once youve written some texts, you can configure your CI server Hudson, in this case to display the unit test results. The figure below shows the checkbox to select and an example of the fileset include it uses the xml file to display the test reports on the Hudson dashboard.
|
Configure Sonar To verify the Sonar Plugin was installed. Go back to the main Hudson dashboard and Select the Manage Hudson link, then select Manage Plugins. From here, select the Installed tab. You should see the Sonar Plugin listed on this tab.
DZone, Inc.
www.dzone.com
Code Coverage
Once youve written some automated tests, you can use a CI server tool like Hudson to determine your overall code coverage - either in the form of line or branch coverage. There are several code coverage tools including Emma, Cobertura, NCover, Clover, etc. This example shows how to configure Hudson to run your existing Cobertura reports. The example below assumes that you have already installed the Cobertura plugin for Hudson. Once this plugin has been installed, the Publish Cobertura Coverage Report checkbox is displayed. NOTE: Sonar aggregates Cobertura results as well.
TOOLS
Build Thresholds Build Threshold Pattern: Notify team members of code aberrations such as low code coverage or high cyclomatic complexity. Fail a build when a project rule is violated. Use continuous feedback mechanisms to notify team members. Antipatterns: waiting for numerous code quality issues to go undiscovered or build up to the point where software maintenance increases or functional features are affected. Hudson provides a way to fail the build based on specific thresholds. This is an implementation of the build threshold pattern. In the example below, you can see that Hudson lets you configure method, line and conditional code coverage targets. If the code in the build doesnt meet these criteria, the build fails. This is an effective to discover and fix potential problems earlier in the development process. The following are not recommended tools, but recommended tool types - with example tools that you might use. There are many more tools available than the list provided here. Its important to realize that you need numerous types of tools to effectively create working software in a single command with every change applied to the version-control repository.
Tool Name CruiseControl Hudson CruiseControl.net Checkstyle PMD FindBugs JavaNCSS FxCop NCover Cobertura Ratproxy JUnit DbUnit Selenium AntUnit JMeter
|
Automated Unit, Database Seeding, Functional, Build, Load, Web Services Testing
Java
DZone, Inc.
www.dzone.com
Ant Maven Buildr NAnt MSBuild Ivy Artifactory Liquibase Java Secure Channel Grand UMLGraph SchemaSpy
Build Tool
Java .Net Ruby Others Ant Java Java Others Java Ant Java Any
JDepend Sonar Subversion Perforce Accurev TFS Git IzPack Email X10 SMS Jabber (IM)
Dependency Manager, Repository Automated Database Upgrades Deployment Build Diagrams UML Documentation ERD Documentation
RECOMMENDED BOOK
For any software developer who has spent days in integration hell, cobbling together myriad software components, Continuous Integration: Improving Software Quality and Reducing Risk illustrates how to transform integration from a necessary evil into an everyday part of the development process. The key, as the authors show, is to integrate regularly and often using continuous integration (CI) practices and techniques.
BUY NOW
books.dzone.com/books/continuous-integrations
Bro
ugh
t to
you
by...
#8
z.co m
it ! V is arz
E: LUD IN C y TS bilit EN onsi NT esp CO of R in Cha and m Com reter rp Inte tor ... ore Itera tor dm dia d an Me rver tho se Me S Ob RN plate TTE Tem
n n n n n n n
ns tter Pa sign De
Cha in e of R ns spo ibil ity, con tinu ed
re le a que st an d th ndle e ha ue req r doe snt st w ith th e ha
one
e to th nce in fere ted k re s lis ctquic PA s, a es a bje ern IGN tt vid s, le O pro n pa DES sab iagram . UT fcard F) desig of Reu r ple s re ss d o ABO oke xam ents des cla ttern our (G Inv de h lem n Pa of F worl suc s: E inclu esig cts D ang attern real ern is D AN Th P obje enting 23 G patt , and a uct MM inal Design . Each m nd str tion ple CO orig ma k re con rma om ir im boo Softwa nt teC d to info the cre Clie the d Use om age nd Con () ns: d fr ente on, us ma ct cute Ori tter Com ) uple s obje nati ( +exe low l Pa eco is al rge cute ch xpla ona ed la e . Th s su . ati nb +exe bject nship form bjects Cre y ca an o tio e d to rate o d as ed rela ms, t th eate Use rith tha e tr ject bas . . ispa ns: lgo b to b er jects lly o g it stem tter many d ge a iv b sy win ona Pa ana allo traditi Rece en o ers. ral en uest ord to m betwe ctu twe req ndled in riant n. sa sed s Stru s be an . in va late catio e ha s: U ilitie psu at c invo to b llbacks es or cture the Enca quest s th ttern sponsib d ca stru nt tim lity. ling re g l Pa ship ng an tiona at varia the hand pose ssin func ueui tion iora , and re ject Pur led k roce to be ob av as q rela us p llbac be hand ed. y the Beh nships n be ed rono tionalit y need ject ed ca to from ch ne b d ca an tio You ne s need asyn func sts is couple ith o that st the rn the without n it is rela que ar ls w ate ips Reque y of re be de cilit d patte ssing entatio particul nsh or Dea e. ould ce Use to fa an r sh A hist pro implem ents its ting. n latio pe: pe used e comm voke for ec m Whe ntim s re al Sco ely toty The in exp th ueue actu d imple wid clas Pro ject ed at ru ue is are utilizing a job q of the ue C Ob ues with y e que the que g to en dg que s. B an en als xy . Job orithm be giv knowle that is terface Pro e ch : De e time g ct b n e in S r le of al ed ca to have d obje of the er mp cop pil rato ut an Exa serv nes ss S at com exec e queue comm Deco Ob confi S Cla e th B d the n . Th for de nge king leto ithin invo hm w Faca cha Sing od tory
n n n n
nd le a outc ay ha an tial hand sm hen oten ject le to . .W le p le ob tern ethod bject be ab tab pat ultip ecific o should cep n M this if the m up the s sp an ac d e ents ject ime. d is be a lem ks to se e passe de to of ob at runt handle imp b Use ec set til co t ld ch ges n A n ined being shou peats un paren ime ngua erm Whe not e la the runt or if it det ore s re uest som d tion proces e no m req g in metho cep n A e e ar a ndlin e ex ack th ther n ha rown in ndle th ll st until ptio th e ca Exce ion is sm to ha up th tered or ral un le cept echani passed avio co ex mp Beh . is en am Exa hen tion uest to has ack. W ject q cep st Ob e re e ex call le th nd th hand s to ha ct obje
ome.
Upcoming Titles
Vaadin Continuous Integration 2 Spring Web Flow Integrating Zend and PHP Resin Flash Builder 4.0 Maven 3
Most Popular
Spring Configuration jQuery Selectors Windows Powershell Dependency Injection with EJB 3 Netbeans IDE JavaEditor Getting Started with Eclipse Very First Steps in Flex
re f c
Download Now
a rd
Refcardz.com
Get
Mo
ef re R
.com
DZone, Inc. 140 Preston Executive Dr. Suite 100 Cary, NC 27513 888.678.0399 919.678.0300
50795
ww
z w. d
tutorials, cheat sheets, blogs, ILITY feature articles, source code and more. NSIB
S
Me
diato m
Me
ento
Ob
or
ject
Beh
avio
ral
ES FR
PO
succ
ess
9 781934 238677
Version 1.0
Copyright 2010 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, 2 ler nt and Clie photocopying, or otherwise, without prior written permission ConcreteHqpublisher. of the uest ( )
ern
Con
cre
teH
and () uest
1 ler
+ha
ndle
re
hand
le a
req
uest
ki by lin
ng
ww
z w.d
one
.c o
$7.95
Build
er
Meth tory Fac t eigh Flyw ter rpre Inte B tor Itera
State
algo
rit
Stra