I'm working with an existing TFS Build and Release Management setup and know little about the (now deprecated) XAML build system it uses.
In this snippet from the build template below my project is built, tests are ran and then a sequence is started which hands the compiled project over to TFS Release Management for deployment.
<Sequence DisplayName="Overall build process">
<mtbac:SetBuildNumber DisplayName="Update build number" BuildNumberFormat="[BuildNumberFormat]" />
<mtbwa:AgentScope DisplayName="Run on agent" MaxExecutionTime="[AgentSettings.GetValue(Of TimeSpan)("MaxExecutionTime", new System.TimeSpan(0,0,0))]" MaxWaitTime="[AgentSettings.GetValue(Of TimeSpan)("MaxWaitTime", 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)("PreActionScriptPath", String.Empty)]" Arguments="[AdvancedBuildSettings.GetValue(Of String)("PreActionScriptArguments", String.Empty)]" />
<mtba:RunMSBuild DisplayName="Run MSBuild" OutputLocation="[OutputLocation]" CleanBuild="[CleanBuild]" CommandLineArguments="[String.Format("/p:SkipInvalidConfigurations=true {0}", AdvancedBuildSettings.GetValue(Of String)("MSBuildArguments", String.Empty))]" ConfigurationsToBuild="[ConfigurationsToBuild]" ProjectsToBuild="[ProjectsToBuild]" ToolPlatform="[AdvancedBuildSettings.GetValue(Of String)("MSBuildPlatform", "Auto")]" RunCodeAnalysis="[AdvancedBuildSettings.GetValue(Of String)("RunCodeAnalysis", "AsConfigured")]" />
<mtba:RunScript DisplayName="Run optional script after MSBuild" FilePath="[AdvancedBuildSettings.GetValue(Of String)("PostActionScriptPath", String.Empty)]" Arguments="[AdvancedBuildSettings.GetValue(Of String)("PostActionScriptArguments", String.Empty)]" />
<mtba:RunScript DisplayName="Run optional script before Test Runner" FilePath="[AdvancedTestSettings.GetValue(Of String)("PreActionScriptPath", String.Empty)]" Arguments="[AdvancedTestSettings.GetValue(Of String)("PreActionScriptArguments", String.Empty)]" />
<mtba:RunAgileTestRunner DisplayName="Run VS Test Runner" Enabled="[Not AdvancedTestSettings.GetValue(Of Boolean)("DisableTests", false)]" TestSpecs="[AutomatedTests]" ConfigurationsToTest="[ConfigurationsToBuild]" />
<mtba:RunScript DisplayName="Run optional script after Test Runner" FilePath="[AdvancedTestSettings.GetValue(Of String)("PostActionScriptPath", String.Empty)]" Arguments="[AdvancedTestSettings.GetValue(Of String)("PostActionScriptArguments", String.Empty)]" />
<mtba:RunTestImpact DisplayName="Get Impacted Tests" Enabled="[AdvancedTestSettings.GetValue(Of Boolean)("AnalyzeTestImpact", 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">
Currently in the event of a test failure the sequence step still executes and the broken build is deployed. I have the "Fail build on test failure" option enabled.
I need to prevent deployments when there are test failures, either by stopping the release step from running or amending the process in release management (I was leaning towards not touching release management at all in the event of a build failure).