我有一个任务在第一次调用时总会失败,因为它缺少一个文件,但我有一个 OnError 任务,它创建文件并恢复其他任务,但构建将始终失败,因为它处于错误状态。无论如何都要在 OnError Target?
中重置此错误状态MSDN声明如下:
如果目标元素之一的任务失败且 ContinueOnError 属性设置为 ErrorAndStop OnError 元素>(或 false )
话虽如此,如果我将 ContinueOnError 设置为 WarnAndContinue (或 true )
,我将无法执行任务这是我的代码:
<PropertyGroup>
<AppVersion>0.0.0</AppVersion>
<ChangelogFileName>Changelog_$(AppVersion).html</ChangelogFileName>
<AppCastLocation>http://test/AppCast.xml</AppCastLocation>
</PropertyGroup>
<!-- AppCastCreation target is the starting point, it attempts to download
the AppCast.xml (Target=AppCastDownload), if it fails then we create
a new AppCast.xml (Target=AppCastNew) and then update the AppCast with
the new version bneing deployed (Target=AppCastUpdate) -->
<Target Name="AppCastCreation">
<CallTarget Targets="AppCastDownload;AppCastUpdate" RunEachTargetSeparately="True" />
</Target>
<Target Name="AppCastDownload">
<!-- Download latest AppCast.xml if it doesn't exist, then create a new one -->
<WebDownload FileUri="$(AppCastLocation)" FileName="AppCast.xml" />
<OnError ExecuteTargets="AppCastNew"/>
</Target>
<Target Name="AppCastNew">
<!-- Create a new AppCast.xml -->
<Message Text="Creating new AppCast.xml" />
<Exec Command='python $(AppCastPublisherPath)AppCastPublisher.py new AppCast.xml "Changelog" "$(AppCastLocation)"'/>
<OnError ExecuteTargets="MessageErrorHandler"/>
</Target>
<Target Name="AppCastUpdate" DependsOnTargets="AppCastDownload">
<Message Text="Updating AppCast.xml with Version $(AppVersion)" />
<!-- Create changeset info and upload -->
<Exec Command="python GetJenkinsChangeset.py -html -out $(ChangelogFileName)" />
<OnError ExecuteTargets="MessageErrorHandler"/>
</Target>
那么无论如何我可以重置我的 AppCastNew 目标中的错误状态,或者可能会执行另一个会执行相同结果的工作流程吗?
答案 0 :(得分:0)
您可以指定<OnError...
值"WarnAndContinue"
,然后使用条件检查$(MSBuildLastTaskResult)
属性,而不是使用ContinueOnError
。
旧:
<WebDownload FileUri="$(AppCastLocation)" FileName="AppCast.xml" />
<OnError ExecuteTargets="AppCastNew"/>
新:
<WebDownload ContinueOnError="WarnAndContinue" FileUri="$(AppCastLocation)" FileName="AppCast.xml" />
<CallTarget Condition=" '$(MSBuildLastTaskResult)' == 'False' " Targets="AppCastNew"/>
(我相信"WarnAndContinue"
和$(MSBuildLastTaskResult)
都是在MSBuild 4.0中引入的。)