Archive

Posts Tagged ‘build’

Remote Admin IIS for TFS 2010 Builds

December 24th, 2009 Craig Tadlock 3 comments

If you are building a web application then one of the key things that needs to be done in the build and deployment process is manipulating a remote IIS server. Your requirements could be as simple as stopping and starting a website or as far as creating websites and application pools on the fly. As I’ve previously discussed the default TFS 2010 build template activities leave much to be desired in this area (read more here).  Lucky for us this is solved fairly easily with a mashup of technologies; Powershell 2.0, appcmd.exe, custom TFS build process templates and custom activities. In this simple example we will do a basic website deployment which includes stopping an existing remote website, deleting the existing files, coping our files to the deployment folder and starting the website back up…

The key to remote IIS administration is Powershell 2.0; it has the ability to run remote commands on servers using WinRM. To setup the build server and deployment server follow these steps. Note these are for Windows Server 2008 R2.

  1. Make sure Powershell 2.0 is installed on both the build agent and deployment server.
  2. Reduce the Powershell execution policy; in Powershell run the command set-executionpolicy RemoteSigned
  3. On the deployment server you will need to enabled remote administration. The simplest way is to run the command winrm -quickconfig and follow the basic questions (all yes). This will enabled administration on HTTP and open a hole in the firewall.
  4. Obviously make sure IIS in installed on the deployment machine.
  5. Make sure the user that will be executing remote commands has the appropriate permissions on the deployment server. For me my user was TFSSERVICE and I gave it administrator rights on the deployment server. You can probably lock the permissions down further if you like.

As a test to make sure this is working outside of the TFS build process try this…

  1. Create a test website (TestWebsite) on the deployment server (DeploymentServer)
  2. On the build server open up a command prompt and run the command: icm deploymentserver “c:\windows\system32\inetsrv\appcmd.exe stop site TestWebsite”
  3. On the deployment server check to see if the website is stopped; if it is then it worked and if not then you will need to debug

Once you have that working you can incorporate it into the TFS 2010 build and deployment system. To make my life easier I created a custom activity to easily execute remote commands; RemoteProcess.xaml. It wraps the InvokeProcess activity and constructs the appropriate Powershell command and handles the errors.

Now it is trivial to implement the above website deployment example. Using the RemoteProcess activity use these as the RemoteCommands and set the RemoteServer argument to DeploymentServer.

Stop Website

“c:\windows\system32\inetsrv\appcmd.exe stop site TestWebsite”

Start Website

“c:\windows\system32\inetsrv\appcmd.exe stop site TestWebsite”

You can see how powerful this is; now you have the ability to execute ANY command on the deployment server. Using this to administer IIS is just the start; this will be useful for SQL server database deployments, windows services, security… anything really.

UPDATE

After working with this for a bit I found a functional bug; the above solution does not return the remote command’s exit code. This is important so that you can have logic for success and failure of the remote command. The solution took me a long time to figure out! The new RemoteCommand should be…

“-noprofile -command “”$x = icm ” + RemoteServer + ” {” + RemoteCommand + “; $lastexitcode}; if ($x.length -gt 1){$x[0]}; exit $x[$x.length - 1]“”"

I created a few arguments on the RemoteProcess activity to support this, Output, Err and ExitCode. So to finish the above example of stopping a website would be…

powershell -noprofile -command “$x = icm DeploymentServer {c:\windows\system32\inetsrv\appcmd.exe stop site TestWebsite; $lastexitcode}; if ($x.length -gt 1){$x[0]}; exit $x[$x.length - 1]“

Custom Build Activities in TFS 2010

November 27th, 2009 Craig Tadlock 2 comments

To build real world applications with TFS you will need to code some custom activities; the ones out of the box are not enough. There are several good resources for how to build these activities (see below). But there are some issues in Beta 2 that make the process a bit difficult. The issue is trying to get your custom activities to show up in the build process template workflow designer. Hopefully this gets fixed in the RTM version, but for now here’s what you can do.

Quick note about my setup, I have a single project that has all the custom workflow activities and several other applications that have their own builds that will use these activities. I dont want copies of my custom activities all over the place.

  1. Create a central solution and project for your custom activities; call the project Workflow
  2. Create your application solution and projects; lets call this solution Sunnyside.
  3. Under your Sunnyside solution root create a folder called Build
  4. Create a solution in this Build folder called BuildProcessTemplates
  5. Branch the Workflow project to BuildProcessTemplates folder. (This allows you to have a central place to code your activities)
  6. In this branched Workflow project create your custom build process template xaml files (Add them to the project; set the build action to None)
  7. Now you will be able to open the BuildProcessTemplates solution, open the xaml file and be able to add the custom activities.

What a pain! Again, I hope this is fixed for RTM. Here are a few references…

How to create a custom workflow activity for TFS Build 2010

TFS Team Build 2010: Working with Custom Code Activities

MSDN Forum Thread

EDIT

After spending way too long on this Ive made some improvements. You dont actually have to branch the custom activities folder over, you can just add a DLL reference. The key is that in order to get the activities to show up in the toolbox you must use the “Choose Items…” -> “System.Activities Components” tab -> “Browse…” to the DLL. If you just add a normal DLL reference it wont work.

Custom Workflow Activities in TFS 2010 TeamBuild

November 21st, 2009 Craig Tadlock No comments

Jim Lamb has a great write up on how to build custom workflow activities for TeamBuild for TFS 2010. Given that some key activities are missing out of the box in beta two, it’s very likely you will find yourself writing a few of your own.

http://blogs.msdn.com/jimlamb/archive/2009/11/18/how-to-create-a-custom-workflow-activity-for-tfs-build-2010.aspx

Cloud Processing for Client Applications

November 16th, 2009 Craig Tadlock No comments

Funny, I was just wondering about something this morning… then I check the latest tech news and sure enough there is an article similar to what I was thinking! So here it is… Cloud/grid computing is all the rage these days. In the current model you put your entire application in the cloud and run it from there. This is good for some things like web servers and databases, but not great for other things. Applications that don’t fit well into the current cloud model tend to be very rich UI focused applications; for example most of the applications you run on your desktop/laptop. However there is a subset of those desktop applications that at time require intense processing power, much more that your little desktop/laptop can provide. Examples of this include compiling code (VS.NET), transcoding audio/video, crazy Excel spreadsheets… What you really want is a local application experience but use the power of the cloud for the intense processing tasks. Imagine this; you are using VS.NET and TFS for a large enterprises system with several applications and databases. When you click rebuild all, it automatically puts your changes into a shelveset on the server, kicks off a server build (which leverages a huge CPU farm of build servers), then when done copies the outputs to your local machine. This would be great for huge systems! At Spot Runner it took 5+ minutes to rebuild the entire solution on the local developer machines. We had the choice of either upgrading 100 engineer’s systems to be more powerful (expensive) or leaving it be and paying the cost in developer productivity (more expensive). This would have solved both problems by giving faster rebuild times and allowing us to maximize the usage of our cap-ex server expenditure by centralizing it. There really isn’t anything stopping this from becoming reality. I could see a model both where the computing-cloud is internal to the corporate network or an external cloud (Amazon, Microsoft, Google…). I have to imagine these companies are already working on this. If you know anything about this, let me know!

http://techflash.com/seattle/2009/11/microsoft_juicing_up_excel.html

Categories: future Tags: , , , ,

TFS 2010 TeamBuild Deployment FAIL

November 16th, 2009 Craig Tadlock 2 comments

TFS TeamBuild has come along way with with 2010; the current version is almost a total rewrite of the previous versions. There are a ton of articles online about what’s great about the new TeamBuild (workflow, lab management, parallel tasks…), but I’m going to cover what’s not so great. Again Microsoft has really ignored the concept of application deployment and has just focused on compiling and testing. This is fine if you are building a DLL, but not if you are building a web application or database… or let alone an enterprises system. To be clear about what I mean by deployment; I’m referring to the process of taking built code and deploying it from a central server environment to the various code environments that exist in your organization (DEV, QA, PROD..). It really is a key step in the process… How are you supposed to test a N-tier web application without 1st deploying the web, service and database components? The closest they come is the new Lab Management functionality; but this is far more focused on managing virtual machines. They should have separated this all out… activities around TFS, activities around compiling, activities around the file system, activities around testing, activities around IIS, activities around databases and activities around virtual servers. A good example on how the default template is almost useless out of the box is that all the outputs from EVERY project in your solution get dropped into one big flat directory. This is the same behavior as in previous versions. What you really want is a folder for each application. this would make it easier to bridge from building to deploying as you have a folder that represents the output of a deployable component that can be copied to another server. You can see my MSDN post about this here…

http://social.msdn.microsoft.com/Forums/en-US/tfsprerelease/thread/9173d13f-88c0-4060-8bbd-2826e2eac8c8

Luckily though this all can be fixed; albeit with some work. It is possible to create both your own workflow activities and your own build process workflows. So I dove into the default build process template to understand what is going on there. From there I’ve started to create my own build process workflow. It’s a work in progress, but for now it at least drops each application’s output into it’s own directory in the drop folder. I will be adding the deployment and test tasks next.

TFS 2010 Vustom Build Process Workflow