防止TFS构建测试失败的开发

时间:2016-06-30 08:24:55

标签: tfs tfsbuild tfs2015 release-management ms-release-management

我正在使用现有的TFS构建和发布管理设置,并且对它所使用的(现已弃用的)XAML构建系统知之甚少。

在下面的构建模板的代码片段中,构建了我的项目,运行了测试,然后启动了一个序列,将已编译的项目交给TFS Release Management进行部署。

<Sequence DisplayName="Overall build process">
<mtbac:SetBuildNumber DisplayName="Update build number" BuildNumberFormat="[BuildNumberFormat]" />
<mtbwa:AgentScope DisplayName="Run on agent" MaxExecutionTime="[AgentSettings.GetValue(Of TimeSpan)(&quot;MaxExecutionTime&quot;, new System.TimeSpan(0,0,0))]" MaxWaitTime="[AgentSettings.GetValue(Of TimeSpan)(&quot;MaxWaitTime&quot;, new System.TimeSpan(4,0,0))]" ReservationSpec="[AgentSettings.CreateAgentReservationSpec()]">
  <mtbac:InitializeEnvironment DisplayName="Initialize environment" />
  <mtbat:TfGetSources DisplayName="Get sources from Team Foundation Version Control" CleanWorkspace="[CleanWorkspace]" CreateLabel="[CreateLabel]" VersionOverride="[GetVersion]" />
  <mtba:AssociateChanges DisplayName="Associate the changesets that occurred since the last good build" UpdateWorkItems="[UpdateAssociatedWorkItems]" />
  <TryCatch DisplayName="Try" mtbwt:BuildTrackingParticipant.Importance="Low">
    <TryCatch.Try>
      <Sequence DisplayName="Compile, Test and Publish">
        <mtba:RunScript DisplayName="Run optional script before MSBuild" FilePath="[AdvancedBuildSettings.GetValue(Of String)(&quot;PreActionScriptPath&quot;, String.Empty)]" Arguments="[AdvancedBuildSettings.GetValue(Of String)(&quot;PreActionScriptArguments&quot;, String.Empty)]" />
        <mtba:RunMSBuild DisplayName="Run MSBuild" OutputLocation="[OutputLocation]" CleanBuild="[CleanBuild]" CommandLineArguments="[String.Format(&quot;/p:SkipInvalidConfigurations=true {0}&quot;, AdvancedBuildSettings.GetValue(Of String)(&quot;MSBuildArguments&quot;, String.Empty))]" ConfigurationsToBuild="[ConfigurationsToBuild]" ProjectsToBuild="[ProjectsToBuild]" ToolPlatform="[AdvancedBuildSettings.GetValue(Of String)(&quot;MSBuildPlatform&quot;, &quot;Auto&quot;)]" RunCodeAnalysis="[AdvancedBuildSettings.GetValue(Of String)(&quot;RunCodeAnalysis&quot;, &quot;AsConfigured&quot;)]" />
        <mtba:RunScript DisplayName="Run optional script after MSBuild" FilePath="[AdvancedBuildSettings.GetValue(Of String)(&quot;PostActionScriptPath&quot;, String.Empty)]" Arguments="[AdvancedBuildSettings.GetValue(Of String)(&quot;PostActionScriptArguments&quot;, String.Empty)]" />
        <mtba:RunScript DisplayName="Run optional script before Test Runner" FilePath="[AdvancedTestSettings.GetValue(Of String)(&quot;PreActionScriptPath&quot;, String.Empty)]" Arguments="[AdvancedTestSettings.GetValue(Of String)(&quot;PreActionScriptArguments&quot;, String.Empty)]" />
        <mtba:RunAgileTestRunner DisplayName="Run VS Test Runner" Enabled="[Not AdvancedTestSettings.GetValue(Of Boolean)(&quot;DisableTests&quot;, false)]" TestSpecs="[AutomatedTests]" ConfigurationsToTest="[ConfigurationsToBuild]" />
        <mtba:RunScript DisplayName="Run optional script after Test Runner" FilePath="[AdvancedTestSettings.GetValue(Of String)(&quot;PostActionScriptPath&quot;, String.Empty)]" Arguments="[AdvancedTestSettings.GetValue(Of String)(&quot;PostActionScriptArguments&quot;, String.Empty)]" />
        <mtba:RunTestImpact DisplayName="Get Impacted Tests" Enabled="[AdvancedTestSettings.GetValue(Of Boolean)(&quot;AnalyzeTestImpact&quot;, true)]" />
        <Sequence DisplayName="Process the release">
          <Sequence.Variables>
            <Variable x:TypeArguments="x:String" Name="buildDirectory" />
          </Sequence.Variables>
          <mtbwa:GetBuildDirectory DisplayName="Get the Build Directory" Result="[buildDirectory]" />
          <If Condition="[ProcessReleaseTokens]" DisplayName="If ProcessReleaseTokens is set">
            <If.Then>
              <Sequence DisplayName="Initialize tokens">

目前,如果测试失败,序列步骤仍会执行,并且部署了损坏的构建。我启用了“失败构建测试失败”选项。

我需要在出现测试失败时阻止部署,无论是通过停止运行发布步骤还是修改发布管理中的进程(我都倾向于在发生构建失败时根本不接触发布管理)。

2 个答案:

答案 0 :(得分:0)

您可以让您的构建只是吐出WebDeploy包(例如DeployTarget = Package),然后在运行PowerShell脚本的工作流结束时有一个 InvokeProcess 来进行实际部署。 / p>

答案 1 :(得分:0)

您可以更新XAML定义模板以实现此目的。有关详细信息,请参阅此问题中的答案:Release management releasing failed builds also - Triggering release from failed builds

如果链接不起作用,请在此处引用:

  
      
  1. 在“If Not DisableTests”下面移动了“如果设置了ReleaseBuild”活动。
  2.   
  3. 将“如果设置了ReleaseBuild”的条件更改为:ReleaseBuild和(treatTestFailureAsBuildFailure = False或   (treatTestFailureAsBuildFailure和(BuildDetail.TestStatus&lt;&gt;   Microsoft.TeamFoundation.Build.Client.BuildPhaseStatus.Failed)))和   BuildDetail.CompilationStatus&lt;&gt;   Microsoft.TeamFoundation.Build.Client.BuildPhaseStatus.Failed
  4.   
  5. 内部“如果ReleaseBuild已设置”活动的其他部分,将WriteBuildMessage的消息更改为:“跳过执行,因为要么   未设置ReleaseBuild或某些测试失败或编译有   失败“
  6.   
  7. 最后签入模板,就是这样,失败的构建将不会被部署。
  8.