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:
- Entering of timesheets (Should be 1 click at the end of the week… not there yet… It is currently 5 clicks + copy/paste)
- Reminding others to send newsletters
- Handling of money, see Ramits blog post about Automating your Personal Finances
and much more…
Let me know what you automate in your life!
Alright back to software…
Today I want to automate our deployment process:
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
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:
- Visual Studio 2010 on developers machines
- Team Foundation Server 2010 as Source control, Project management and Build tool
- 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?
- Configure the deployment package of your project in VS2010
- Let your Build server create this deployment package for you
- Create a folder on your Build server, for all your deployment batch files
- Configure your settings for your specific environment in "YourProject.SetParameters.xml"
- Create a batch file that launches "YourProject.deploy.cmd"
- Write some info in a file called history.txt about the successful deployment (might come in handy later)
- When
- Who
- What
- To Where
- Double click and deploy!!!
The details
1. Configure the deployment package of your project
Figure: Check these settings in VS2010
2. Let your Build server create this deployment package for you
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
- I had to use the parameter -allowUntrusted on msdeploy, because our certificate on the server is unsigned
- 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 - 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 - See if you can deploy from VS2010 to that server, if that doesn't work you should investigate that problem first
- Deployment still fails: Exclude IIS settings in VS2010 and try again
- When something doesn't work and you get:
- System.IO.IOException: The device is not ready
- 401, 404 or 500 HTTP errors
- Run the batch files with msdeploy on the server itself locally to get more debug info
- Check your server logs for more debug info
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…
Warning: Don't be afraid of a deep dive with msdeploy
6 comments:
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
You basically have to alter the MSBuild arguments to get it working like so :
/p:DeployOnBuild=true;DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;_PackageTempDir="c:\temp";AutoParameterizationWebConfigConnectionStrings=false
@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)
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!
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
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