One of the fields that ships with the standard Bug Work Item Type in Team Foundation is called “Found In Build”. It allows the user to enter the build number of the build in which they found the bug. It can be found on the Details tab of the Bug work item.

The “Found In Build” field starts off with the value “<None>” in its drop down list. As Builds are created with Team Foundation Build Automation, the build number is added to this list. This is accomplished by a subscription to the Build Completion Event that was created during installation.

Unfortunately, the default subscription listens for ALL build completions. In other words, even builds that have compilation errors or fail tests, still make it into the list. This can be a real problem for shops that do frequent builds.

The solution is rather simple to say: Remove the default subscription and replace it with a new filtered subscription. But how do you actually do it? Here are the manual steps (the attached solution contains the quick answer):

  1. Find out the ID of the original subscription. This is actually the tough part. There is no easy way to list the existing subscriptions. So, you have to write some code. The code is rather simple.
    1. Get the list of subscriptions by writing a console app (see the attached project ListSubscriptions)
    2. You need to add references for Microsoft.TeamFoundation.dll and Microsoft.TeamFoundation.Client.dll. These references are for IEventService and TeamFoundationServer respectively.
    3. Run the app with your server name as an argument. If you don't see any subscriptions (by default there are four), you may need a different user name. Change your app to take the username as the second command line argument. Pass in the user name of the person that installed the server. If you aren't sure who that is, see this link on how to list the subscriptions from the database.
    4. Look for the subscription that has an EventType of BuildCompletionEvent and a Delivery Address like http://<tfservername>/WorkItemTracking/v1.0/Integration.asmx. That’s the one we want to change. Write down the id.
  2. Create a new subscription like the one we want to change, but with a filter. Unfortunately, you can’t update a subscription. So, you have to delete the old one and create a new one. For this step we can use the BisSubscribe.exe tool (available at %programfiles%\Microsoft Visual Studio 2005 Team Foundation Server\TF Setup\BisSubscribe.exe on the server).
    1. Determine the filter string to use. In my tests I used the following filter string to filter out all builds that failed for any reason. (I will probably add another blog soon to discuss the other filters that might be of interest).

Filter ==> "CompletionStatus"='Successfully Completed'

    1. Remove the old subscription.

BisSubscribe.exe /unsubscribe /id <idFromStep1> /server <tfservername>

    1. Add the new subscription. (Take careful note of the single and double quotes used in the filter string)

BisSubscribe.exe /eventType BuildCompletionEvent /address http://<servername>/WorkItemTracking/v1.0/Integration.asmx /deliveryType Soap /server <tfservername> /filter "\"CompletionStatus\"='Successfully Completed'”

  1. Rerun your console app to make sure your new subscription is in place.

Note: The attached solution contains two projects:

  • ListSubscriptions - simply lists the subscriptions; this is the program described in step 1 above.
  • SubscribeToGoodBuildsOnly - does exactly what the steps above describe how to do by hand. It will replace the correct event for you or tell you if it couldn't find one. You can even specify a different filter string to use instead of the one described above.