laurentkempe / StatiqBlog

My blog https://laurentkempe.com/
https://laurentkempe.com/
3 stars 1 forks source link

Nuke target build time #32

Open laurentkempe opened 2 years ago

laurentkempe commented 2 years ago

Graph time spent running tests or any target ran by nuke build Add a custom build metric to be able to fail the build

Image

See https://twitter.com/laurentkempe/status/1562741381021716482

See https://www.jetbrains.com/help/teamcity/2021.2/build-failure-conditions.html#Adding+Custom+Build+Metric

Image

Image

You can also use code to report a metric

protected override void OnTargetSucceeded(string target)
{
    base.OnTargetSucceeded(target);

    if (!target.Equals(nameof(Tests))) return;

    var testsTarget = SucceededTargets.SingleOrDefault(executableTarget => executableTarget.Name.Equals(nameof(Tests)));
    if (testsTarget == null) return;

    Serilog.Log.Information("Tests succeeded in {BCTestsTargetRunDuration}", testsTarget.Duration);

    TeamCity.Instance?.AddStatisticValue("BCTestsTargetRunDuration", testsTarget.Duration.ToString());
}