Executing a custom TFS 2010 BuildActivity on the Controller

Most of the time when you create a custom Build Activity for TFS 2010 you want it to run on the Build Agent. Occasionally, you will come across a situation where you need your activity to execute as the very first thing before the build has even started or as the very last thing after the build is finalized. It’s very easy to configure your custom Build Activity to run on the controller. All Build Activities classes have the BuildActivity attribute. This attribute takes one argument, HostEnvironmentOption, which has four options: Agent, Controller, All, or None.

[BuildActivity(HostEnvironmentOption.All)]
public sealed class SendEmailActivity : CodeActivity
{

By setting the HostEnvironmentOption to All or Controller we can run our custom Build Activity on the build controller. The Agent option will restrict the activity to the build agent. Most of the time I use the All option unless I have a good reason not to.

If you don’t use the right HostEnvironmentOption you will get an error like the following:

TF215097: An error occurred while initializing a build for build definition \Internal\Test Build Definition: The build process failed validation. Details: Validation Error: The private implementation of activity ‘1: DynamicActivity’ has the following validation error: TF28000: Activity ‘SendEmailActivity’ must be used in the context of an AgentScope.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>