Wednesday, 28 December 2016

How To Automate Build Process of ASP.NET Websites using Jenkins and MSBuild

How to build ASP.NET websites using Jenkins

Introduction

Jenkins offers out of the box build solution for Web application, but it becomes difficult to build an ASP.NET website. This article describes step by step how websites can be built using Jenkins.

Background

I had to offer an auto building solution to one of the clients that I was working for. It was an ASP.NET wesite and had dependant projects also. Jenkins could build web applications seamlessly. But there when it comes to website, it becomes an issue.

Using the Code

Pre-requisites

Install Visual Studio .NET 4.0
Install SQL Server management studio 2008 R2
Install Tortoise SVN
Download and install Jenkins Windows native package from http://jenkins-ci.org/

Download and Install MSbuild Extension pack from the below mentioned location:

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.
5. 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 to 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:
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.

MSbuild script code (The MSbuild script file that was added in the previous step - SourceCodeBuild.msbuild)

<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>


No comments:

Post a Comment