martes, 5 de enero de 2010

Configurando Cruise Control .net + svn + MS Test desde 0

Hace poco incursioné en el mundo de la integración continua. Les dejo una breve guía de cómo configurar un Cruise Control .net + svn + MS Test desde 0.

1. Instalar CCnet http://confluence.public.thoughtworks.org/display/CCNET/Download.

2. Bajar nAnt http://nant.sourceforge.net/ y copiar a directorio local (yo los copié en c:\archivos de programa).

3. Bajar nAnt Contrib http://nantcontrib.sourceforge.net/ y copiar a directorio local.

4. Bajar svn command line http://nantcontrib.sourceforge.net/ y copiar a directorio local.

5. Configurar un proyecto de build en ccnet.config, ubicado en el directorio de instalacion de CCnet. Es recomendable hacer esto paso por paso, para ir probando como funciona

<cruisecontrol cb="urn:ccnet.config.builder">
<!-- This is your CruiseControl.NET Server Configuration file. Add your projects below! -->
<project>
<name>myProject</name>

<!-- Step1: trigger build from commit, check every 60 seconds -->
<triggers>
<!--<intervaltrigger seconds="60" buildcondition="ForceBuild">-->
<intervaltrigger name="Subversion" seconds="60">
</triggers>

<!-- configure svn repository -->
<sourcecontrol type="svn">
<trunkurl>http://svn.com/myProject/trunk/src/</trunkurl>
<workingdirectory>C:\Archivos de programa\CruiseControl.NET\server\myProject\WorkingDirectory\Source</workingdirectory>
<username>user</username>
<password>pass</password>
<executable>C:\Archivos de programa\CollabNet\Subversion Client\svn.exe</executable>
</sourcecontrol>
<tasks>
<!-- Step 2: Build solution -->
<nant>
<executable>C:\Archivos de programa\nant-0.85\bin\nant.exe</executable>
<buildfile>cruise.build</buildfile>
<targetlist>
<target>run</target>
</targetlist>
</nant>
<!-- Step 3: Run tests -->
<exec>
<!--Call a batch file that contains del testResults.trx -->
<!--this is required as MsTest will not create the file if it exists-->
<!--this could be merged with the mstext action in a single batch file-->
<executable>deleteTestLog.bat</executable>
<basedirectory>C:\Archivos de programa\CruiseControl.NET\server\myProject\WorkingDirectory</basedirectory>
<buildargs></buildargs>
<buildtimeoutseconds>30</buildtimeoutseconds>
</exec>
<exec>
<!--Call mstest to run the tests contained in the TestProject -->
<executable>C:\Archivos de programa\Microsoft Visual Studio 9.0\Common7\IDE\mstest.exe</executable>
<basedirectory>C:\Archivos de programa\CruiseControl.NET\server\myProject\WorkingDirectory\Source</basedirectory>
<!--testcontainer: points to the DLL that contains the tests -->
<!--runconfig: points to solutions testrunconfig that is created by vs.net, list what test to run -->
<!--resultsfile: normally the test run log is written to the uniquely named testresults directory -->
<!-- this option causes a fixed name copy of the file to be written as well -->
<buildargs>/testcontainer:Test\bin\Debug\Test.dll /runconfig:LocalTestRun.testrunconfig /resultsfile:testResults.trx</buildargs>
<buildtimeoutseconds>120</buildtimeoutseconds>
</exec>
</tasks>
<publishers>
<!--to get the test results in the dashboard we have to merge the results XML file -->
<!--the project working directory is used as the base path here -->
<merge>
<files>
<file>Source\testResults.trx</file>
</files>
</merge>
<!--this is the line I missed for ages, without it you get strange missing publisher log errors -->
<xmllogger>
</publishers>
</project>
</cruisecontrol>

Este es el archivo cruise.build que compila la solución VS2008 usando nNant (ubicado en C:\Archivos de programa\CruiseControl.NET\server\myProject\WorkingDirectory):

<?xml version="1.0"?>
<project default="run">
<property name="nant.settings.currentframework" value="net-3.5">
<property name="MSBuildPath" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe">
<property name="SolutionFile" value="C:\Archivos de programa\CruiseControl.NET\server\myProject\WorkingDirectory\Source\myProject.sln">
<property name="SolutionConfiguration" value="Debug">

<target name="run" depends="build">
</target>

<target name="build">
<exec program="${MSBuildPath}">
<arg line="'">
<arg line="/property:Configuration=${SolutionConfiguration}">
<arg value="/target:Rebuild">
<arg value="/verbosity:normal">
<arg value="/nologo">
<arg line="'/logger:">
</exec>
</target>
</project>

6. Configurar dashboard. Simplemente hay que crear un virtual directory en IIS y apuntarlo a C:\Archivos de programa\CruiseControl.NET\webdashboard.

Luego ingresar a http://localhost/ccnet, para ver que el dashboard funciona. Debería verse el proyecto de build. Para agregar los resultados de los test hay que entrar a administer dashboard e instalar MS Test Results y modificar los plugins de dashboard.config (ubicado en C:\Archivos de programa\CruiseControl.NET\webdashboard)

<buildplugins>
<buildreportbuildplugin>
<xslfilenames>
<xslfile>xsl\header.xsl</xslfile>
<xslfile>xsl\modifications.xsl</xslfile>
<xslfile>xsl\MsTestSummary2008.xsl</xslfile>
<xslfile>xsl\compile.xsl</xslfile>
</xslfilenames>
</buildreportbuildplugin>
<buildlogbuildplugin>
<xslreportbuildplugin description="MSTest Report" actionname="MSTestBuildReport" xslfilename="xsl\MsTestReport2008.xsl"></xslreportbuildplugin>
<xslreportbuildplugin description="NAnt Output" actionname="NAntOutputBuildReport" xslfilename="xsl\NAnt.xsl"></xslreportbuildplugin>
<xslreportbuildplugin description="NAnt Timings" actionname="NAntTimingsBuildReport" xslfilename="xsl\NAntTiming.xsl"></xslreportbuildplugin>
</buildplugins>

7. Instalar CC Tray. Esta es una aplicación que corre en el system tray y que muestra mediante semáforos el estado del build. La aplicación se baja desde el dashboard. Luego se agrega el servidor de build y se selecciona el proyecto de que se quiere monitorear.

Algunos links que me fueron útiles

Tutoriales:
http://confluence.public.thoughtworks.org/display/CCNET/Resources
http://www.codeproject.com/KB/dotnet/cruisecontrol_continuous.aspx

Configurar frw 3.5:
http://codebetter.com/blogs/jeffrey.palermo/archive/2007/11/28/upgrade-nant-for-use-with-vs2008-solutions-and-net-3-5.aspx

Configurar build:
http://stackoverflow.com/questions/1195389/msbuild-task-or-msbuild-exe-with-nant

Configurar MS Test:
http://blogs.blackmarble.co.uk/blogs/bm-bloggers/archive/2006/06/14/5255.aspx
http://stackoverflow.com/questions/362208/mstest-failing-in-2008-from-build-script


saludos!

No hay comentarios.: