次の方法で共有


How to filter the Build Completion Event

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 https://<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 https://<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.

SubscriptionHelpers.zip

Comments

  • Anonymous
    September 05, 2006
    As soon as folks start using Team Build, especially with some sort of continuous integration support,...

  • Anonymous
    September 06, 2006
    In my previous post (How to filter the Build Completion Event), I explained how to change the filter...

  • Anonymous
    December 10, 2006
    I received some questions from a local and very sophisticated development shop asking about Team Foundation

  • Anonymous
    December 24, 2006
    Some FAQs that I collected while navigating lots of sites that a lot of people do ask about TFS that...

  • Anonymous
    January 10, 2007
    In my previous post ( How to filter the Build Completion Event ), I explained how to change the filter

  • Anonymous
    May 13, 2008
    In an previous post (long long ago), I described some scenarios around why you would want to subscribe

  • Anonymous
    December 04, 2009
    Is it possible to create a subscription where it will notify you only when the compilation result changes from failure to success or vice versa? I was looking for something like this under the BuildCompletionEvent: "TeamProject" = 'Project1' AND "StatusCode/OldValue" = 'Succeeded' AND "StatusCode/NewValue" = 'Failed' "TeamProject" = 'Project1' AND "StatusCode/OldValue" = 'Failed' AND "StatusCode/NewValue" = 'Succeeded' I know the schema for the BuildCompletion does not have a NewValue OldValue property, but I was just wonder if there was some other way to accomplish the same result. Thanks for any help on this!!

  • Anonymous
    December 06, 2009
    Unfortunately, the Build Completion Event only provides information on the current state of the build. It does not fire when the status changes. Note that the Status Changed Event is misnamed and is really a Build Quality Changed event. It fires whenever the Build Quality of the build changes. Sorry for the bad news. Hopefully in a future version we will address the need to capture changes like this in an event. Thanks, Jason

  • Anonymous
    April 07, 2011
    I just found this and I am trying to filter the build completion events for VSTS 2010.  Unfortunately, it doesn't seem to work.  The code compiles, with warnings about using obsolete classes.  When I run it, I am unable to find any event subscriptions.  Does this code need to be updated to work with VSTS 2010, or is there another way to filter the Build Completion Events? Thanks.