TFS Build CopyDirectory error not stopping build

1.1k views Asked by At

I have a CopyDirectory step in my build template, and I was assuming that if it finds a directory that does not exist, it would throw errors. However, it is only throwing a warning, and the build itself is marked successful.

I've tried to wrap it around a try/catch block, and manually did a 'throw' exception step, but still didn't work. I tried to set the buildStatus to failed, but that didn't work either. Any another way I can achieve this? I don't want the build to be successful if any of the copy directory fails.

EDIT:

Here is the snippet where the copy directory is. I'm looping over a list of servers and copying a bunch of directories.

<ForEach x:TypeArguments="x:String" sap2010:WorkflowViewState.IdRef="ForEach`1_4" Values="[SCCDServers]">
                <ActivityAction x:TypeArguments="x:String">
                  <ActivityAction.Argument>
                    <DelegateInArgument x:TypeArguments="x:String" Name="server" />
                  </ActivityAction.Argument>
                  <Sequence sap2010:WorkflowViewState.IdRef="Sequence_37">
                    <mtbwa:CopyDirectory Destination="[server]" DisplayName="Copy Code Files" sap2010:WorkflowViewState.IdRef="CopyDirectory_14" Source="[BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCWebOutputFolder]" />
                    <mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_16" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[&quot;Code Files copied to &quot; &amp; server]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
                    <mtbwa:CopyDirectory Destination="[server]" DisplayName="Copy Config Files" sap2010:WorkflowViewState.IdRef="CopyDirectory_15" Source="[BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCConfigSourceFolder &amp; &quot;\&quot; &amp; SCCDServerRole]" />
                    <mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_17" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[&quot;Config Files copied to &quot; &amp; server &amp; Environment.NewLine &amp; &quot;Copied from: &quot; &amp; BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCConfigSourceFolder &amp; &quot;\&quot; &amp; SCCDServerRole]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
                    <mtbwa:CopyDirectory Destination="[server]" DisplayName="Copy Sitecore Files" sap2010:WorkflowViewState.IdRef="CopyDirectory_16" Source="[BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCSitecoreFilesSourceFolder]" />
                    <mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_18" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[&quot;Sitecore Files copied to &quot; &amp; server &amp; Environment.NewLine &amp; &quot;Copied from: &quot; &amp; BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCSitecoreFilesSourceFolder]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
                  </Sequence>
                </ActivityAction>
              </ForEach>
3

There are 3 answers

0
Jonathan On BEST ANSWER

CopyDirectory indeed has a bug that only issues a warning when the source directory doesn't exist. It also has problems with long paths (>248 chars).

Possible workarounds:

  1. Use InvokeCommand, running Robocopy.exe (better than xcopy) and checking its resultcode.
  2. If you must use CopyDirectory, check yourself that the source directory exists.
4
Isaiah4110 On

Why dont you make use of the "InvokeProcess" activity then?

  1. Select the activity, open the Variables tab at the bottom.
  2. Add a variable "ResultCode" of type Int32. This variable will contain the exit code from the copy process.
  3. Add the "InvokeProcess" activity to your workflow.
  4. Open the "InvokeProcess" activity and drop a "WriteBuildMessage" activity inside the Handle Standard Output section.
  5. Set the Importance property to Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High. Set the Message property to stdOutput.
  6. Drop an instance of the WriteBuildError activity to the Handle Error Output section Set the Message property to errOutput
  7. Now Set "InvokeProcess" properties FileName: "xcopy" Agruments: "Source" "Destination" \s \e \y Result: ResultCode
  8. Check the "ResultCode" value. I use an IF activity and check for the condition "ResultCode <> 0". Within the "THEN" section add a "THROW" activity and add the exception: "New Exception("Error copying files")

Details here

0
suresh2 On

If copy fails, Set setbuildproperties status to failed in your custom workflow.

        <mtbwa1:SetBuildProperties DisplayName=“Set build status failed“  PropertiesToSet=“Status“ Status=“[Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed]“ />

http://msdn.microsoft.com/en-us/library/bb399143(v=vs.100).aspx