Tuesday, November 20, 2012

TFS Build: Unable to create the workspace 'xxx' due to a mapping conflict

Right. You get this one, so you go to your build agent and delete a workspace manually.
If you are reading this post to find only how to delete a workspace, here it is get and go:

C:\Program Files (x86)\Microsoft Visual Studio 11.0>tf workspace /delete /collection:CollectionURL WorkspaceName /login:BuildServerAccount

If you want to know some more - keep reading :)

So, after a while problem comes again. And again. One day (I think it was 3rd time I got to delete workspace manually) I actually asked myself a question - why does this happen?

When a workspace is fetched\created by the agent during build, it uses a template for workspace name, which is defined in the build template used for your build defintition. Like this:


<Assign x:TypeArguments="x:String" DisplayName="Initialize Workspace Name" To="[WorkspaceName]"
Value="[String.Format(&quot;{0}_{1}_{2}&quot;, BuildDetail.BuildDefinition.Id, Microsoft.TeamFoundation.LinkingUtilities.DecodeUri(BuildAgent.Uri.AbsoluteUri).ToolSpecificId, BuildAgent.ServiceHost.Name)]" mtbwt:BuildTrackingParticipant.Importance="Low" />

And now imagine you have several build templates, and each has its own way for naming a workspace. Not a big deal, seems to be?... but wait. At some point a build definition decides to change to another build template. And everything is same for the build, but the workspace naming.
Build starts at the same agent. Since it is another naming template for the workspace, agent tries to create a new workspace - and oops, there is already mapping for this source control folder. Kabum! Mapping conflict.

How to fix it? Use same workspace naming template throughout all your build templates. 

PS: Many thanks to Jakob Ehn, who helped me to figure this out. 

No comments:

Post a Comment