Breaking Builds

The Cake.Issues addin can be used to break builds if specific issues were reported.

List of all aliases for breaking builds

See all available Aliases for breaking builds

To break builds you need to import the following core addin:

build.cake
#addin nuget:?package=Cake.Issues&version=5.5.0
Build.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Cake.Frosting" Version="5.0.0" />
    <PackageReference Include="Cake.Issues" Version="5.5.0" />
  </ItemGroup>
</Project>

The following task will fail the build if any issues were added to the issues global variable:

build.cake
// Global issues list into which issues need to be added.
IEnumerable<IIssue> issues = null;

Task("BreakBuildOnIssues")
    .Description("Breaks build if any issues in the code are found.")
    .Does(() =>
{
    BreakBuildOnIssues(issues);
});
Program.cs
using Cake.Core;
using Cake.Frosting;

public static class Program
{
    public static int Main(string[] args)
    {
        return new CakeHost()
            .UseContext<BuildContext>()
            .Run(args);
    }
}

public class BuildContext(ICakeContext context) : FrostingContext(context)
{
    private readonly List<IIssue> _issues = [];

    public IEnumerable<IIssue> Issues { get { return _issues;  } }

    public void AddIssues(IEnumerable<IIssue> issues)
    {
        _issues.AddRange(issues);
    }
}

[TaskName("BreakBuildOnIssues")]
public sealed class BreakBuildOnIssuesTask : FrostingTask<BuildContext>
{
    public override void Run(BuildContext context)
    {
        context.BreakBuildOnIssues(context.Issues);
    }
}