Mike Vincent's Blog

Community, Software Architecture, Application Lifecycle Management

August 2010 - Posts

Building a Custom Build Workflow with Deployment

Exploring Team Build based on Workflow 4.0 in Visual Studio 2010 ALM

 

With Visual Studio 2010 Application Lifecycle Management, Team Build is based on Workflow 4.0. Workflow provides an improved build experience and allows you to customize the workflow to suit your specific automation needs. Out of the "box" the default build workflow does not include deployment. Here I will show you how to add a simple deployment to a user acceptance test (UAT) location.

 

To begin, in the Team Explorer for your subject team project right click on Builds and select New Build Definition. Give the new build definition a name and supply the necessary information for the other tab pages. For Process, we are deriving our new process template from the default template. I'll give you a link to my custom process template at the end of this post and you can optionally specify that if you choose to.

 

Derive from existing process template

Your new process template will be saved on the TFS server. I'm using the default storage location. Double-click on the file name to check it out from source control and open it. The file will open in the Workflow XAML designer. Be patient as it takes a while for everything to load.

 

Source Control Explorer

 

The workflow will open in compressed or collapsed mode. I have opened the "Run on Agent" activity here. We will focus on the "Try Compile, Test, and Associate Changesets and Work Items" activity since that is where we want to add our deployment. If you are new to workflow based builds, spend some time exploring the tools and the template process workflow in order to understand what happens when and under what conditions.

Run On Agent

In the "Try Compile, Test, and Associate Changesets and Work Items" activity, expand the Finally block. I have added a new activity at the end called "If DropBuild Successful". Expand the activity.

 

Try Compile, Test, and Associate ...

 

Note the condition. When it resolves to true, the Then block will execute. I've added an activity of type Sequence called "DeployUAT" that contains our actual deployment functionality. Since we only want to deploy to our UAT manually, I have added an Invoke for Reason activity and named it "InvokeOnlyForManual". You should see the dropdown for Reason set to 'Manual" in the properties.

If DropBuild Successful

 

I have scoped new variables and arguments to the "DeployUAT" activity. These allow us to define where our UAT site is located and what it's name is. Click on the Variables and Arguments tabs at the bottom of the designer.

 

Variables

 

Arguments

 

While on the Arguments tab, open Metadata. Here I have defined a new category that will show up in the build process dialog. I have named this category "Deployment" and it displays our 2 new parameters with their default values.

 

Metadata

 

Now to move on to the actual  work of deployment. First we need to stop the UAT web site. I do this in an InvokeProcess activity I have named "InvokeStopWebsite" that calls appcmd.exe and passes the argument "String.Format("stop site {0}", UATWebsiteName)" to stop the site as a VB expression.

 

Stop Website

 

Stop argument

 

Next, I need to delete existing content from the UAT site. I do this with an InvokeProcess activity that I named "InvokeDeleteWebsiteFiles" where I call cmd.exe and pass the argument "/c del *.* /s /q" to delete all files. Be careful when testing destructive operations during development to be sure you are executing against the intended target.

 

Delete content

 

I then copy our newly built content to the UAT site with another InvokeProcess activity I named "InvokeCopyWebsiteFilesFrom".  Again I call cmd.exe and pass the argument "/c xcopy ""{0}/_PublishedWebsites/Tailspin.web"" {1} /s /e, BuildDetail.DropLocation, UATDirectory)" to xcopy the files from the drop location to our UAT site.

Copy new content

 

Finally, I restart the UAT web site with the InvokeProcess activity named "InvokeStartWebsite". I call appcmd.exe and pass the argument "String.Format("start site {0}", UATWebsiteName)" to start the site.

 

Start Website

 

That concludes our simple deployment customization. Save your XAML file and check it in to source control. You now have your custom template ready for use. Below you can see our Deployment category that we added to the template process. The default values can be over-ridden when the process is manually called.

 

Build Properties

This custom example should get you started on adding deployment to your builds. There are many more considerations you may have to make for your particular implementations. Considerations include, security and crossing firewall boundaries. You may need a much higher degree of sophistication and may need to consider coding custom activities. Here's a summary in increasing order of complexity.

Compose as a composite activity in XAML
Inherit from CodeActivity
Inherit from AsyncCodeActivity
Inherit from NativeActivity
Create using DynamicActivity


Download
Custom Process Template 1

Urban Turtle - Check it out

Accentient, who I work with to provide ALM training and consulting, is pleased to announce that they are officially a friend of the Urban Turtle.

Accentient is both an Urban Turtle “Select Partner”, which is a highly recognized and trusted organization that can provide you with various services to make you successful with Scrum TFS and Urban Turtle as well as a Professional Scrum Developer (PSD) Select Partner who has demonstrated unique value in delivering the PSD course.

Urban Turtle is an intuitive Scrum tool for TFS built to simplify your software development cycles. It was built by experienced Scrum coaches and practitioners, Urban Turtle helps you deliver kick-ass software sustainably, every iteration. It provides you a fast, intuitive tool to plan. manage and track your Scrum work.

Urban Turtle

Check out the YouTube video, get the 30 day trial (you'll want the full version before your trial is up) and start sprinting.