Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to do nightly deployment of ASP.NET MVC 3 Website?

I have an ASP.NET MVC 3 Website in C# with

  • ASP.NET MVC 3 Internet Project
  • Domain Project (Class Library)
  • Unit Testing Project
  • SQL Server 2008 R2 Database
  • Source Control on Mercurial

What is the easiest way to do a 12:00AM automated nightly build and deployment of the site so that everyday I could go to dev.mycompany.com and would see a live updated version of my Dev version?

I was thinking of using Jenkins to do all of the building.

like image 581
Max Alexander Avatar asked Dec 06 '11 17:12

Max Alexander


1 Answers

I help maintain a system much like this -- in Jenkins. Obviously the details will vary based on your project structure, but here's roughly what our Jenkins job does:

  • Pull code (we use Git but there's a Mercurial plugin for Jenkins as well)
  • Execute any SQL schema changes against our testing DBs from an idempotent script (we use an Ant script which pre-dates our use of Hudson/Jenkins)
  • Run msbuild (another Jenkins plugin)
    • Build file is our .sln (or you can use a web .csproj -- the arguments are slightly different)
    • Command line arguments:
      • /p:Configuration=Dev /p:Platform="Any CPU" /p:DeployOnBuild=true /p:DeployTarget=Package /p:DeployIisAppPath="dev.mycompany.com/" /v:m
    • This builds a .zip file, a .cmd file, and some .xml files, which contain everything you need to deploy updates to your site
  • Kick off two other "msdeploy" Jenkins jobs, one on each .NET web server
    • Each .NET web server is also a Jenkins slave
    • We have two servers in testing, balanced via NLB
    • Each "msdeploy" job copies the .zip/.cmd/.xml files from the build server to a temporary location on the web server and then runs the .cmd file
    • The .cmd file executes msdeploy, which pushes everything you need out to your dev web server

We have a separate job that runs our NUnit tests, but you could just as easily incorporate your tests into your main job. One of the reasons we build the whole .sln instead of the web .csproj is so we can run our unit tests from the same built code.

If you haven't already, you will need to install ASP.NET MVC3, .NET 4, and msdeploy on the build server, and I believe you'll need most of the same files on your web servers as well.

For scheduling, you can choose "build periodically" or "poll SCM" as your build trigger, and then use cron-like syntax (0 0 * * *) to run daily at midnight.

like image 148
Paul Karlin Avatar answered Sep 28 '22 03:09

Paul Karlin