Problem:
Team build cannot create Scrum for Team System bug on build
failure.
warning : TF42097: A work item could not be created due to a
field error. The following fields have incorrect values: Field: 'Reason' Value:
'Build Failure'
Solution:
Add ‘Build Failure’ as a reason to the Bug Work Item type.
Code:
<TRANSITION from="" to="Not Done">
<REASONS>
<DEFAULTREASON value="New"
/>
<REASON value="Build Failure" />
</REASONS>
</TRANSITION>
Explanation:
The problem is that when the build script
attempts to create a bug for a build failure it is trying to set the reason for
the bug to ‘Build Failure’. ‘Build
Failure’ is not a valid reason in the Scrum for Team System bug work item. To add ‘Build Failure’ as a valid reason start
the Visual Studio 2008 Command Prompt and use witExport to export the bug work
item type. The witExport command you
need to use is below:
witexport /f bug.xml /t http://tfsServer:8080 /p teamProject /n bug
Replace tfsServer with your TFS server name
and replace teamProject with the name of the team project you want to export
the work item from. This command will
result in a file bug.xml to be saved on your hard drive with the bug work item
type definition. Open the file with your
favorite xml editor.
Change
<TRANSITION from="" to="Not Done">
<REASONS>
<DEFAULTREASON value="New"
/>
</REASONS>
</TRANSITION>
To
<TRANSITION from="" to="Not Done">
<REASONS>
<DEFAULTREASON value="New"
/>
<REASON value="Build Failure" />
</REASONS>
</TRANSITION>
Save the file and use witImport to import the modified bug
work item type into your team foundation server. The witImport command you need
to use is below:
witimport /f bug.xml /t http://tfsServer:8080
/p teamProject
Replace tfsServer with your TFS server name and replace teamProject
with the name of the team project you want to import the work item into. This command will result in the new work item
type definition being stored for that team project.
Now when your build fails the work item
will be created.
Another alternative is to simply update the value passed as
the reason of the bug from ‘Build Failure’ to ‘New’. To do that you simply change the following line
in your tfsbuild.proj file.
Change
<WorkItemFieldValues>System.Reason=Build
Failure;System.Description=Start the build using Team Build</WorkItemFieldValues>
To
<WorkItemFieldValues>System.Reason=New;System.Description=Start
the build using Team Build</WorkItemFieldValues>
I guess one final option is to simply skip creating the work
item all together. Add this to the first
Property Group:
<SkipWorkItemCreation>true</SkipWorkItemCreation>
You can also change the template used to create your
tfsbuild.proj file by changing C:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE\PrivateAssemblies\1033\TFSBuild.proj so you don’t have to
change every tfsbuild.proj file after build creation.