我的构建模板中有一个 CopyDirectory 步骤,我假设如果它找到一个不存在的目录,它会抛出错误。但是,它只是发出警告,并且构建本身被标记为成功。
我尝试将它包裹在 try/catch block 中,并手动执行“抛出”异常步骤,但仍然无效。我试图将 buildStatus 设置为失败,但这也不起作用。还有其他方法可以实现吗?如果任何复制目录失败,我不希望构建成功。
编辑:
这是复制目录所在的片段。我正在遍历服务器列表并复制一堆目录。
<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 & "\_PublishedWebsites\" & SCWebOutputFolder]" />
<mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_16" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="["Code Files copied to " & 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 & "\_PublishedWebsites\" & SCConfigSourceFolder & "\" & SCCDServerRole]" />
<mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_17" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="["Config Files copied to " & server & Environment.NewLine & "Copied from: " & BuildDetail.DropLocation & "\_PublishedWebsites\" & SCConfigSourceFolder & "\" & 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 & "\_PublishedWebsites\" & SCSitecoreFilesSourceFolder]" />
<mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_18" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="["Sitecore Files copied to " & server & Environment.NewLine & "Copied from: " & BuildDetail.DropLocation & "\_PublishedWebsites\" & SCSitecoreFilesSourceFolder]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
</Sequence>
</ActivityAction>
</ForEach>
最佳答案
CopyDirectory
确实有一个错误,它只会在源目录不存在时发出警告。它还存在长路径问题(>248 个字符)。
可能的解决方法:
- 使用
InvokeCommand
,运行Robocopy.exe
(优于xcopy
)并检查其结果代码。 - 如果您必须使用
CopyDirectory
,请自行检查源目录是否存在。
关于c# - TFS 构建 CopyDirectory 错误不停止构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18796008/