在CruiseControl.NET 1.8.4中,我正在运行一个包含多个MsBuild-Tasks的项目。项目配置的简短摘录,由CCValidator解析和验证:
<tasks>
<msbuild>
<buildArgs>msbuild-base.xml /m /p:BuildInParallel="true";Configuration="Release";Platform="Any CPU";nr="false";ccversionbase=15.1.0;NuGetProjectDir=D:\REPO\Repo-Base /verbosity:minimal /nologo /target:PreBuild</buildArgs>
<dynamicValues />
<environment />
<executable>C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe</executable>
<logger>"C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll"</logger>
<loggerParameters />
<priority>Normal</priority>
<timeout>120</timeout>
<workingDirectory>D:\BaseLibraries</workingDirectory>
</msbuild>
<msbuild>
<buildArgs>msbuild-other.xml /m /p:BuildInParallel="true";Configuration="Release";Platform="Any CPU";nr="false";ccversionbase=15.1.0;revfile=D:\REPO\Repo-Base\ci-revision.xml /verbosity:minimal /nologo /target:CIFull</buildArgs>
<dynamicValues />
<environment />
<executable>C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe</executable>
<logger>"C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll"</logger>
<loggerParameters />
<priority>Normal</priority>
<timeout>120</timeout>
<workingDirectory>D:\BaseLibraries</workingDirectory>
</msbuild>
</tasks>
还有很多任务,但这足以解释问题。所有任务都有不同的msbuild文件,并且不是同一文件中的目标。
对于项目的成功构建运行,前几个任务必须成功完成。因此,当任务失败时,CC.NET停止构建是完美的。但如果其中一个后续任务失败,我想让CC.NET继续执行下一个任务,而不是停止整个构建。
如何配置CC.NET以忽略失败的任务并继续下一个?
答案 0 :(得分:1)
如果您将可能始终在发布商部分中运行的任务放在 无论他们是否失败,他们都会被碾压。
如果订单如下,则会出现问题: MayNotFail,MayFail,MayFail,MayNotFail
对于那种情况,我无法立即想到解决方案
答案 1 :(得分:1)
当其中一个任务失败时,CruiseControl.NET让构建停止并失败。即使一个任务失败,我希望在触发所有任务的情况下完成构建。奖励:如果一个失败,我希望构建状态为“失败”,但不会停止第一个失败事件。
所以我将所有非关键(“可选”)任务放入一个额外的MsBuild-Script中:
<Project DefaultTargets="CIFull" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MsBuildAgent>"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"</MsBuildAgent>
<MsBuildArguments>msbuild.xml /m /p:BuildInParallel="true";Configuration="Release";Platform="Any CPU";nr="false";ccversionbase=$(ccversionbase);revfile=$(revfile);buildplans=$(buildplans) /verbosity:minimal /nologo /target:CIFull /nr:false</MsBuildArguments>
</PropertyGroup>
<Target Name="Libraries">
<Exec Command="$(MsBuildAgent) $(MsBuildArguments)" WorkingDirectory="$(buildplans)\MyLibraryOne" IgnoreExitCode="false" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="LibExitCode01" />
</Exec>
<Exec Command="$(MsBuildAgent) $(MsBuildArguments)" WorkingDirectory="$(buildplans)\MyLibraryTwo" IgnoreExitCode="false" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="LibExitCode02" />
</Exec>
<Exec Command="$(MsBuildAgent) $(MsBuildArguments)" WorkingDirectory="$(buildplans)\MyLibraryThree" IgnoreExitCode="false" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="LibExitCode03" />
</Exec>
</Target>
<Target Name="Applications">
<Exec Command="$(MsBuildAgent) $(MsBuildArguments)" WorkingDirectory="$(buildplans)\ApplicationOne" IgnoreExitCode="false" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="AppExitCode01" />
</Exec>
<Exec Command="$(MsBuildAgent) $(MsBuildArguments)" WorkingDirectory="$(buildplans)\ApplicationTwo" IgnoreExitCode="false" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="AppExitCode02" />
</Exec>
<Exec Command="$(MsBuildAgent) $(MsBuildArguments)" WorkingDirectory="$(buildplans)\ApplicationThree" IgnoreExitCode="false" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="AppExitCode03" />
</Exec>
</Target>
<Target Name="ValidateExitCodes">
<ItemGroup>
<Failed Condition="$(LibExitCode01) != 0" Include="MyLibraryOne" />
<Failed Condition="$(LibExitCode02) != 0" Include="MyLibraryTwo" />
<Failed Condition="$(LibExitCode03) != 0" Include="MyLibraryThree" />
<Failed Condition="$(AppExitCode01) != 0" Include="ApplicationOne" />
<Failed Condition="$(AppExitCode02) != 0" Include="ApplicationTwo" />
<Failed Condition="$(AppExitCode03) != 0" Include="ApplicationThree" />
</ItemGroup>
<ItemGroup>
<Success Condition="$(LibExitCode01) == 0" Include="MyLibraryOne" />
<Success Condition="$(LibExitCode02) == 0" Include="MyLibraryTwo" />
<Success Condition="$(LibExitCode03) == 0" Include="MyLibraryThree" />
<Success Condition="$(AppExitCode01) == 0" Include="ApplicationOne" />
<Success Condition="$(AppExitCode02) == 0" Include="ApplicationTwo" />
<Success Condition="$(AppExitCode03) == 0" Include="ApplicationThree" />
</ItemGroup>
<Message Importance="High" Text="*** Success: @(Success->Count()) (@(Success, ' '))" />
<Message Importance="High" Text="*** Failed: @(Failed->Count()) (@(Failed, ' '))" />
<Error Text="*** FAILED: @(Failed, ' ') ***" Condition="'@(Failed->Count())' > 0" />
</Target>
<Target Name="CIFull" DependsOnTargets="Libraries;Applications;ValidateExitCodes" />
</Project>
现在,它们现在列在上面的MsBuild文件中,而不是将每个“可选”库和应用程序作为任务添加到CC.NET项目中。 CC.NET配置修改如下:
<tasks>
<msbuild>
<!-- When this task fails, the build shall stop and fail -->
<buildArgs>msbuild-base.xml /m /p:BuildInParallel="true";Configuration="Release";Platform="Any CPU";nr="false";ccversionbase=15.1.0;NuGetProjectDir=D:\REPO\Repo-Base /verbosity:minimal /nologo /target:PreBuild</buildArgs>
<dynamicValues />
<environment />
<executable>C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe</executable>
<logger>"C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll"</logger>
<loggerParameters />
<priority>Normal</priority>
<timeout>120</timeout>
<workingDirectory>D:\BaseLibraries</workingDirectory>
</msbuild>
<msbuild>
<!-- This task is the new build file from above. -->
<buildArgs>msbuild-new.xml /m /p:BuildInParallel="true";Configuration="Release";Platform="Any CPU";nr="false";ccversionbase=15.1.0;revfile=D:\REPO\Repo-Base\ci-revision.xml;buildplans=D:\Meta\BuildPlans /verbosity:minimal /nologo /target:CIFull</buildArgs>
<dynamicValues />
<environment />
<executable>C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe</executable>
<logger>"C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll"</logger>
<loggerParameters />
<priority>Normal</priority>
<timeout>120</timeout>
<workingDirectory>D:\Meta</workingDirectory>
</msbuild>
</tasks>
CC.NET首先完成第一项任务。如果失败,则不执行任何其他任务并报告错误。没关系,CC.NET继续完成第二项任务。
现在,所有的lib和应用程序都是构建的 - 忽略(但保存)返回值(目标Libraries
和Applications
)。目标ValidateExitCodes
现在创建一个成功和失败任务的列表 - 在所有任务运行之后。如果失败任务的列表包含一个元素,则会向CC.NET返回错误。 CC.NET会将构建状态设置为错误。