TeamBuild blocked on publish symbols activity

I recently had an issue with TFS TeamBuild where the builds would get stuck if you configured the build definition to publish symbols. The build would hang at the Publish Symbols activity for an hour and timeout causing the build to fail.

The symbol server share location requires exclusive access during publishing, its a file based database. Therefore a shared resource lock is placed within the Team Project Collection where the build definitions reside. To find out which locks are in place open a SQL Server Management Studio window and within the TPC database you can view all locked resources running the following query…

select * from tbl_SharedResource where LockedBy is not null

Locks may remain in place, if for example the build controller crashed during a build and failed to release the lock. This will subsequently cause all builds to hang.

To remove the lock you can run the following stored procedure…(replace the requestedby parameter with the build controller in the above query that holds the lock)

DECLARE@RCint
DECLARE@partitionIdint
DECLARE@resourceNamenvarchar(256)
DECLARE@instanceIdnvarchar(64)
DECLARE@requestedBynvarchar(256)
SET@partitionId=1
SET@resourceName=NULL
SET@instanceId=NULL
SET@requestedBy=‘vstfs:///Build/Controller/34′
EXECUTE@RC=[dbo].[prc_ReleaseSharedResourceLock]
@partitionId
,@resourceName
,@instanceId
,@requestedBy

I would just like to stress making changes to your database without support from Microsoft is not recommended and therefore I take no responsibility for loss or issues arisen from the use of the above scripts.

Just one final tip as each TPC manages its own resource locks – its a good idea not to share the same UNC path for multiple TPC’s as this could also result in access errors.

 

Adding back the MSBuild MultiProc option in TfvcTemplate.12.xaml

I have recently been updating our build infrastructure to TFS2013 and noticed the option to run MSBuild in multi proc (or not) is no longer available in the new TFS process templates TfvcTemplate.12.xaml. This has caused some issues that only manifest in multi proc mode. (my particular issue was with using sandcastle)

Luckily its an easy few steps to add this option back…

Step 1 – I find it useful when working with templates to place them within a class library to get all the relevant assembly references. Create a new project and add to source control.

Step 2 – Download the template. TFS2013 now stores the default template in a global location, i.e. so you don’t have multiple copies of this template in each Team Project. However you need edit this and check it back into TFS. Create a new Build Definition, Process Tab, Show Details and you get the option to download the template.

1

Step 3 – Add a reference to Microsoft.TeamFoundation.Build.Common

Step 4 – Edit the Workflow Argument “AdvancedBuildSettings”. Add a new value for MSBuildMultiProc default of True, complete object constructor is…

New Microsoft.TeamFoundation.Build.Common.BuildParameter(” { “”MSBuildArguments””: “”””, “”MSBuildPlatform””: “”Auto””, “”PreActionScriptPath””: “”””, “”PreActionScriptArguments””: “”””, “”PostActionScriptPath””: “”””, “”PostActionScriptArguments””: “”””, “”RunCodeAnalysis””: “”AsConfigured””, “”MSBuildMultiProc””: “”True”” } “)

Step 5 – Edit the Metadata argument. Click on ellipse button to bring up the editor, add a new value with the following settings…

2

Step 6 – On the workflow find the “Run MSBuild” activity and bring up the properties window. Set the MSBuildMultiProc value to…

Boolean.Parse(AdvancedBuildSettings.GetValue(Of String)(“MSBuildMultiProc”, “True”))

3

Step 7 – Check into Source Control

Step 8 – Create a new build definition using the new template.

4

Bingo – we now have the option to turn is back on and off again.