3

I am using Cake to build a solution on a TeamCity build server.

Currently, my build statistics are not at the point where I'd like them to be - for example, I can obtain total runtime for my tests in the Tests tab in TeamCity, and I can see the individual running time for these tests there, as well as the total run time of the build.

However, if I'd like to see how much time a particular step has been taking over time, I'd have to do it manually.

For example, given the below sample from an execution

[17:09:22]  [Step 1/1] Clean                                00:00:00.0301134    

[17:09:22]  [Step 1/1] Update-Version                       00:00:00.0826397    

[17:09:22]  [Step 1/1] Restore-Node-Packages                00:00:32.2691674    

[17:09:22]  [Step 1/1] Restore-NuGet-Packages               00:00:09.2550592    

[17:09:22]  [Step 1/1] Build-UI                             00:00:07.4544697    

[17:09:22]  [Step 1/1] Build                                00:04:12.2181356  

For a quick fix, I manually parsed this using Excel. I could wrangle up a script to parse this output, but I'd really rather not!

1) Is there a way for cake to output each step as a different build step so that TeamCity's graphs and statistics can naturally organize things?

2) If not, can I output the cake task results to some form of file? A CSV or XML would be fine, because I could at least go download them, or include them in the artifacts section, or something.

Thanks JM

José Maia
  • 310
  • 5
  • 21
  • 1
    I am not sure if this covers tour use case exactly, but best advice would be to take a look at this: https://github.com/agc93/Cake.BuildSystems.Module – Gary Ewan Park Jun 20 '17 at 17:16

2 Answers2

6

Yes this is possible, the easiest way is probably using the Cake.BuildSystems.Module which can be fetched from nuget.org

With TeamCity it will provide :

  • Build Logs are separated (and nested) for each executed task
  • Current/ongoing build status is updated to currently running task
  • Error logging aliases are highlighted in build log output

Installation

Using the latest bootstrapper

If you're using the latest bootstrapper example (always available in this repo), you can simply add a tools/Modules/packages.config file with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<packages>
     <package id="Cake.BuildSystems.Module" version="0.1.2" />
</packages> 
devlead
  • 4,935
  • 15
  • 36
6

I do this on my build.cake file.

if (TeamCity.IsRunningOnTeamCity)
{
    // This block makes the teamcily log collapsible by Task
    TaskSetup(ctx => TeamCity.WriteStartBlock(ctx.Task.Name));
    TaskTeardown(ctx => 
    {
        TeamCity.WriteEndBlock(ctx.Task.Name);
        // This service message makes the Tasks duration visible as a statisticValue
        var duration = ctx.Duration.TotalMilliseconds.ToString("0");
        Information("##teamcity[buildStatisticValue key='Block." + ctx.Task.Name + ".Duration' value='" + duration + "']");
    });
}

It does 3 things:

  • Build Logs are separated (and nested) for each executed task
  • Current/ongoing build status is updated to currently running task
  • Adds a build statistic for the duration of each step
pitermarx
  • 908
  • 1
  • 9
  • 22
  • I'm going to give this a shot. You could suggest this / submit a PR with the build statistics to the module described in the accepted answer (https://github.com/agc93/Cake.BuildSystems.Module). It implements the collapsible logs, but does not have (that I can see, at least), the build statistics information. – José Maia Jun 21 '17 at 13:30
  • Raised an issue to suggest this change - https://github.com/agc93/Cake.BuildSystems.Module/issues/11 – David Gardiner Apr 18 '18 at 06:33
  • @pitermarx just to clarify, is the `buildStatisticValue` key name something you just made up, or is that naming convention understood/used by TeamCity? – David Gardiner Jul 09 '18 at 05:46
  • Straight from the docs https://confluence.jetbrains.com/display/TCD18/Build+Script+Interaction+with+TeamCity – pitermarx Jul 10 '18 at 08:50