Wednesday, April 20, 2011

Continuous Integration and remote deployment for SharePoint

This is a short guide of setting up a Continuous integration server and integrating with different plugins to analyse the code quality. At the end of the pipeline, we'll deploy to a remote staging server. The core idea is to build the solution on top of open source stack rather than  proprietary solutions like TFS.

Setting up Continuous Integration server:

  • Although there are tons of CI tools available in the market,as CruiseControl.Net looked for great for integrating various tools we picked up CruiseControl for our implementation.
  • Install CruiseControl.Net on a designated build server
  • CC.NET supports various source control blocks CVS,Subversion,VSS,SourceGear, StarTeam etc.
  • Download a command line client for the source control repository, for Subversion download this CollabNet Subversion command line client
  • Upon successful installation, browse to the folder C:\Program Files\CruiseControl.NET and open ccnet.config file in a text editor.
  • Add the project level detail

<project name=" testProject">
<workingDirectory>C:\develop\project1WorkingDir </workingDirectory>
</project>
  • Add source control block, which contains the SVN repository end point and credentials required to access these resources.
<sourcecontrol type="svn">
<trunkUrl>svn://Foo/trunk</trunkUrl>
<Working Directory>C:\develop\project1WorkingDir </workingDirectory>
<username>ccnet </username>
<password> ccnet </password>
</sourcecontrol>
  • Now we've added a Subversion URL with required credentials to access 
  • Let's add a Trigger block to tell the integration server at what frequency it should get latest and do a build. set the frequency as 360 seconds.
<triggers>
<intervalTrigger name="Subversion" seconds="360" buildCondition="ForceBuild" />
</triggers>
  • Add a Task block for building the solution, CC.net supports various build automation engines such as MSBuild, VSDevenv,NAnt  etc. We'll configure for MSBuild.
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
<WorkingDirectory>C:\develop\project1WorkingDir</workingDirectory>
<projectFile>Sampleprojects.sln</projectFile >
<executable>
</tasks>
  • Alternatively if you want to use Visual studio to build the solution, following fragment will be helpful
<devenv>      
<solutionfile>C:development\Foo.sln</solutionfile>
        <configuration>Debug</configuration>
        <buildtype>Clean</buildtype>
        <executable>C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe</executable>        <buildTimeoutSeconds>360</buildTimeoutSeconds>
      </devenv>
  •  Add an Executable Task in this section after the build task for integrating other third party analysis tools like Microsoft FxCop for static code analysis, SPDisposeCheck tool for memory leak test, Microsoft StyleCop etc.
</exec>
<exec executable="C:\Program Files\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe">      <buildArgs>C:Foo\bin</buildArgs>
</exec>
  • Above Exec snippet requires all binaries to be stored in a single folder to run SPDisposeCheck, this can be done by adding a post build command in CS Project files.
  • Integrate Unit test case execution tools and code coverage tools like MSTest and NUnit test.
Package and move to staging server
  • Add a Exec task tag for WSP Builder
<exec executable="C:\Program Files\WSPTools\WSPBuilderExtensions\WSPBuilder.exe"><baseDirectory>C:\Foo\solutions</baseDirectory>      <buildTimeoutSeconds>360</buildTimeoutSeconds></exec>
  • Add a task which executes a xcopy command to move all these wsp packages to a staging server
<exec executable="C:\WINDOWS\system32\xcopy.exe">
<buildArgs>C:\Foo\Solutions\Output.WSP\*.wsp \\md-stagingSvr\share</buildArgs></exec>
Remote deployment with Sysinternal's PSExec

  • Add  another exec task to invoke PSExec tool to do the remote deployment
  • Alternatively if you have Windows Powershell in these machines you can make use of power shell to do the remote deployment.
<exec executable="C:\SysinternalsSuite\psexec.exe">
<buildArgs>\\md-stagingSvr-u "md-stagingSvr\aravind" -p 123$ "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe" -o addsolution -filename c:\share\output.wsp</buildArgs></exec>


No comments: