Thursday 23 April 2015

Step by Step Guide To Automate Build Process of Asp.net websites using Jenkins and MSBuild


Pre-Requisite

  1. Install Visual Studio .Net 4.0
  2. Install Sql Server management studio 2008 R2.
  3. Install Tortoise SVN.
  4. Download and install Jenkins Windows native package from http://jenkins-ci.org/.
Download and Install MSbuild Extension pack from the below mentioned location-
 http://msbuildextensionpack.codeplex.com/releases/view/85522

Setting up Jenkins for Source Code

Add plugin to jenkins

  1. Open the URL http://localhost:8080/  in browser.  
  2. Click on Manage Jenkins.
  3. Navigate to "Manage Plugin" section.
  4. Click on available tab.
  5. Install Msbuild plugin(Click on install without restart)
  6. Restart Jenkins

Creating a new project in jenkins

  1. Follow all the steps mentioned in "Add plugin to jenkins".
  2. Click on New job
  3. Choose "Build a free-style software project" option. Add job name and click on "OK". It creates a new project to be built.

Configuration of the project

  1. Click on the newly created project.
  2. Click on configure
  3. Under "Source Code Management" choose Subversion module option.
  4. Fill the 'Repository URL' textbox with the corresponding sourcecode URL of SVN. 
          Exp- http://svn.xyz.com/svn/admin
         Note- it may ask for credentials. Please fill the credentials for SVN(which you use to log in to       SVN) so that jenkins application can access SVN. Refer the below image.



    5. Click on 'Add build Step' button and choose 'Build a visual studio project or solution using       MsBuild' option.
   6.  Fill the details as shown in the below image.



Note- MsBuild file should be the build script file from local directory.
  7. Click on save.
  8. Build the project
  9. Build details can be seen on the console output section on the left hand navigation panel.

Scriptfile code-

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProductVersion>10.0.11107</ProductVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    </PropertyGroup>
    <Target Name="PrecompileWeb">
        <AspNetCompiler
            VirtualPath="/TestWebSite"
            PhysicalPath="C:\Test-CI\SourceCode\TestWebSite"
            TargetPath="c:\precompiledweb\TestWebSite\"
            Force="true"
            Debug="true" />
    </Target>
</Project>

 Note- The target path in the build script is the location to which your compiled files would be pushed. the user needs to create these path before hand.