Test runs created using Gated build or MsTest.exe can’t be managed from Microsoft Test Manager (MTM.exe) as they are not associated with a specific Test plan. Since such test runs can’t be managed using current tools, they keep accumulating at TFS over a period of time. To delete such runs one need to query and delete them programmatically. Alternatively you can use attached utility to delete such runs.
TCMRuns /teamprojectCollection:CollectionUri /teamProject:projectName /Action:List|Delete /Age:OlderThanNdays /filter:filterKind /Output:detailed|summary
filterKind is Auto|Manual|NoBuild|<custom>. Auto to filter Automated test run. Manual to filter manual test run. NoBuild to filter test run which has no build associated with it. <Custom> - specify anything which can be used in where clause of ITestRunHelper.Query().
/Action:List is default when not specified.
/Output: Information to print about each test run. Summary is default and includes Title, Id and completionDate.
/teamProjectCollection and /teamProject is required.
Auto Deleting the Test Runs (or Test Results) from Gated Build
It is also possible to configure the build Retention policy in build definition such that when a build gets deleted test artifacts associated with build also gets deleted. By default this is disabled and one has to specifically enable it. To enable it select and edit appropriate build definition. Under “Retention Policy”, make sure that “What to Delete” has “Test Results” selected.