Do you automate your deployment process? (aka Continuous Deployment)

As you may know I am a big fan of automation. I try to automate as many things in my life as possible.
Major reason for automating, is:
I don't have to worry about those "things" anymore, and can focus on other nice "things".

"Things" to automate:

Let me know what you automate in your life!

Alright back to software…

 

Today I want to automate our deployment process:

image
With 1 button click I want to deploy the latest working version of our software to a certain environment.
In my case that's our Staging environment that we show off to users around Australia.

To give you an idea what I am after

Automated Deployment
Figure: I want this red circled Batch file (or PowerShell script) that deploys to a Staging environment

 

We use mainly Microsoft products and tools to setup this environment. Consisting of:

  1. Visual Studio 2010 on developers machines
  2. Team Foundation Server 2010 as Source control, Project management and Build tool
  3. IIS 7 and SQL Server 2008 R2 as hosting platform

 

How can I deploy the latest working version from our TFS Build server to Staging?

  1. Configure the deployment package of your project in VS2010
  2. Let your Build server create this deployment package for you
  3. Create a folder on your Build server, for all your deployment batch files
    1. Configure your settings for your specific environment in "YourProject.SetParameters.xml"
    2. Create a batch file that launches "YourProject.deploy.cmd"
    3. Write some info in a file called history.txt about the successful deployment (might come in handy later)
      1. When
      2. Who
      3. What
      4. To Where
  4. Double click and deploy!!!

The details

1. Configure the deployment package of your project

image
Figure: Check these settings in VS2010

2. Let your Build server create this deployment package for you

image
Figure: Check these settings in VS2010 on your build configuration

3. Create a folder on your Build server, for all your deployment batch files

Logon to your build server and locate the files necessary for deployment, normally

YourProject.deploy-readme.txt
YourProject.deploy.cmd
YourProject.SetParameters.xml
YourProject.SourceManifest.xml
YourProject.zip

Create a copy of YourProject.SetParameters.xml and specify your specific parameters for your environment

Create a batch file that launches YourProject.deploy.cmd with the necessary parameters

Append to history.txt some info about the deployment

DONE!

 

 

Here some pitfalls during my journey

  1. I had to use the parameter -allowUntrusted on msdeploy, because our certificate on the server is unsigned
  2. Additional I had to use the parameter /A:basic, because I am using HTTP basic authentication over SSL to connect to the Management Service.
    Note: Required if the remote server is not using Windows Authentication to identify the user
  3. Make sure the Management Service is running on the server to deploy
    http://weblogs.asp.net/scottgu/archive/2010/09/13/automating-deployment-with-microsoft-web-deploy.aspx
  4. See if you can deploy from VS2010 to that server, if that doesn't work you should investigate that problem first
  5. Deployment still fails: Exclude IIS settings in VS2010 and try again
  6. When something doesn't work and you get:
    - System.IO.IOException: The device is not ready
    - 401, 404 or 500 HTTP errors
    1. Run the batch files with msdeploy on the server itself locally to get more debug info
    2. Check your server logs for more debug info
      clip_image001

 

 

References for deep dive into this topic

Automating Deployment with Microsoft Web Deploy
http://weblogs.asp.net/scottgu/archive/2010/09/13/automating-deployment-with-microsoft-web-deploy.aspx

Nice blog post about MS Deploy basics
http://raquila.com/software/ms-deploy-basics/ 

MSDN - ASP.NET Web Application Project Deployment Overview
http://msdn.microsoft.com/en-us/library/dd394698.aspx

Common Web Deploy connection errors
http://blogs.iis.net/msdeploy/archive/2010/09/22/common-web-deploy-connection-errors-and-recipes-for-fixing-them.aspx

How does Web Deployment with VS 10 & MSDeploy Work?   from Vishal Joshi
http://vishaljoshi.blogspot.com/2009/03/how-does-web-deployment-with-vs-10.html

 

 

Conclusion

The setup of this automated deployment process is not easy and quick to do, but definitely worth having.
Think of all the hours that you have spent releasing a new version of your app. All these hours are saved in the future, and because this process is automated, it is less error prone.

That leads me to final suggestion.
How do you validate if your deployment was successful?
Make sure to have a zsValidate page, by following Do you have a zsValidate page to make sure your website is healthy?

Next step on my Deployment journey is Continuous Deployment to an internal Dev-test environment. Stay tuned. Should be easy now…

 

image
Warning: Don't be afraid of a deep dive with msdeploy

6 comments:

TomPester said...

I have done the continuous deployment scenario and got it working after a lot of research. The actual implementation is not so difficult. Let me know if you need some assistance.

Regards, Tom

TomPester said...

You basically have to alter the MSBuild arguments to get it working like so :

/p:DeployOnBuild=true;DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;_PackageTempDir="c:\temp";AutoParameterizationWebConfigConnectionStrings=false

Peter Gfader said...

@TomPester

Does this deploy automagically to c:\temp?

I was thinking about adding some tasks to the build config on the build server... (DefaultTemplate.xaml)

TomPester said...

Hello Peter,

Indeed it does deploy to c:\temp

There is not need to add tasks although it's certainly possible that way. In fact, I used a currently unsupported feature to make that msbuild work.

You can contact me over at my profile if you have any questions

http://www.blogger.com/profile/04589781214492505594

Good luck!

TomPester said...

Indeed, it deploys to c:\temp

Adding tasks and unzipping the package as you suggest is also an option and can be the best way depending on the situation.

In, fact the MSBuild arguments that I posted are unsupported although I have word that they will be supported in the future or have a trivial workaround.

Let me know (post) how it goes or if you need some input. You can contact me over at my profile.

Regards, Tom

Peter Gfader said...

In this StackOverflow answer are more msbuild parameters for future reference...


http://stackoverflow.com/questions/2636153/how-can-i-get-tfs2010-to-run-msdeploy-for-me-through-msbuild/2656714#2656714

Post a Comment

Latest Posts

Popular Posts