It’s non-obvious how to delete items from Team Foundation Server. Things can be removed from the web interface or from team foundation explorer but they can lurk around still and bother you. It’s surprising difficult to delete. These are the ways that I’ve cleaned up after myself in Team Foundation Server 2013 and 2015.
Workitems – Bugs and Backlog Items
The straightforward way is just to set the status to removed.
But depending on how you construct your queries they’ve a habit of shining through again. To me, there is a difference between “a bug has been created and I had a bit of a think about it and I think it’s not relevant” to “I’ve just completely created the wrong thing and I want to get rid of it”. So if you never want to see the workitem again then it’s down to the command line
witadmin destroywi /collection:http:/{/tfsservername:port}/tfs/{collectioname} /id:{workitemid}
e.g.
witadmin destroywi /collection:http:/myserver:8080/tfs/DefaultCollection /id:678
and it’s gone. Careful now – once it has gone then it’s gone forever.
Builds
On the face of it, it is straightforward to delete builds. Just go to team explorer find the build, right click and press delete.
The problem with this is that the build still exists in some sense and is included when calculating build version number.
Example
Build definition is
MyBuild_1.2.3$(Rev:.r)
Visible in the advance tab of the build definition
The build includes the build revision token (Rev:.r) which increments by 1 for every build
MyBuild_1.2.3.0 MyBuild_1.2.3.1
If we want to delete the send build then fine – go to the web UI and press delete. If the build is requeued we will get
MyBuild_1.2.3.0 MyBuild_1.2.3.2
The build label jumps to 2 missing out 1. The deleted build still exists and counts towards incrementing the build revision token. This might not be an issue. However if you use the build label to drive out the version of the application as we do then this can become a significant issue. Suddenly a version has been missed which could cause various shades of confusion, upset and terror.
To avoid the TFS related terror scenario then the build needs to be deleted AND destroyed. Once again jumping to the command line
To delete the build (i.e. the same as through team explorer)
TFSBuild delete /collection: http:/{/tfsservername:port}/tfs/{collectioname} /builddefinition:{ProjectName}/{BuildName} {BuildLabel}
Now destroy the build so it is completely gone
TFSBuild destroy //collection: http:/{/tfsservername:port}/tfs/{collectioname} /builddefinition:{ProjectName}/{BuildName} {BuildLabel}
Example
TFSBuild delete /collection:http:/myserver:8080/tfs/DefaultCollection /builddefinitionMyProject/MyBuild MyBuild_1.2.3.1
Now destroy the build so it is completely gone
TFSBuild destroy http:/myserver:8080/tfs/DefaultCollection /builddefinitionMyProject/MyBuild MyBuild_1.2.3.1
Now when the build is deleted the build versions work as expected and the revision number is reused i.e.
MyBuild_1.2.3.0 MyBuild_1.2.3.1
Work Item History
This is trickier still, the situation where you put some errant information in a Bug or PBI and want to remove it. It could be innocuous as posting in the wrong bug post (which I have done many times). It could be as eye wateringly bad as three paragraphs of invective targeted at a colleague. Sadly the cmd line doesn’t expose a way to delete work item history.
The only way I know is to code against the TFS object model and delete from there. The object model isn’t that well documented but it’s not bad to code against. One for a future post perhaps,
A note on the command line
The command tools used here (TFSBuild and witadmin) along with other helpful tools such as tf.exe, are found in program files at
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
I would recommend putting this filepath on your PATH environmental variable if you find yourself doing much TFS admin. That way you won’t have to continually navigate to the program files folder. You’ll soon get sick if doing that if you have do delete something from TFS more than a few times.
Useful Links
A full list of build tokens for XAML based builds
https://www.visualstudio.com/en-us/docs/build/define/general
Details of programming against TFS object model
https://msdn.microsoft.com/en-us/library/bb130146(v=vs.120).aspx
Amending PATH variable on a windows machine
http://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/