I just came across a post on the MSDN TFS forums that was asking how you go about assigning the workitem created on a failed build to a specific user. I have also been asked to do this in my organization.
Team Build will create a new workitem in your Team Project when a build fails. The “task” is assigned to the account that ran the build. In my case, that account is a build service account. One of my Dev Leads asked how we could modify the build process to make the assignment to him whenever one of his builds failed. I didn’t have time to look into it, so I pretty much blew him off. I recently had some time to look back into this subject.
I figured that I’d probably have to override the CreateWorkItem target to add an additional “AssignedTo” parameter to the call, but after looking through the interface for that task (using the wonderful Reflector program by Lutz Roeder) I came to the realization that the CreateWorkItem task doesn’t expose an AssignTo property. After a little experimentation and research I came to realize that the TFSBuild.proj file has a property called WorkItemFieldValues which is a semi-colon delimited list of work item object property names and values of properties that are not exposed directly by the CreateWorkItem task. So all you have to do is add an additional name-value pair called “Assigned To” to the property, like so:
10: Assigned To=St. Jean, Steven;
11: Symptom=build break;
12: Steps To Reproduce=Start the build
13: using Team Build
One thing to notice, the “Assigned To” property has a space in the name, “AssignedTo” doesn’t work. Upon first glance, you would think that the Value for the Assigned To property would be the user’s credentials in the for DOMAINUsername but that isn’t so. If you do use the DOMAINUsername for the Value, a workitem will not be created for the build failure and you will receive the following message in your build log:
MSBUILD : warning : TF42095: A work item could not be created for build failure. An invalid value was passed for field Assigned To.
To get the work item to be assigned correctly you have to use the person’s name as it appears in other TFS workitems with the format LastName, FirstName. So as you can see above, the failed build workitem will be assigned to me using the key-value pair of Assigned To=St. Jean, Steven;.
A complete list of the keys that you can use in this property can be found in the MSDN documentation on the CoreField enumeration.
I hope this saves someone else a bit of time and frustration.