Improving development with Cake

Continuous Integration is an important part of any modern software development process, the ability to rapidly and confidently build, test and deploy code in an automated and repeatable way enables you to move quicker and be more responsive, whether that is delivering new features or fixing production issues.

Currently, our continuous integration pipeline uses GitHub, TeamCity and Octopus to store, build and deploy our code. Although this is a great start, there are occasions where a developer needs to make changes, which would stop another developer from using the pipeline. For example, one developer on one branch of code wants to add an Integration Test project to one of the micro-services; another developer working on the same service but in a different branch of code wants to make a change to the database. As they are on different branches of code, neither can see the others’ changes, and neither want to merge their branches together, because then they would be coupled and must be delivered at the same time, slowing development down. Given they both need a successful build on the build server, if the first developer changes the build steps to include the new test project, the build will fail for the second developer. If the second developer removes the new test project from the build steps, the first developer won’t have confidence that their new tests are passing.

Adding Cake

Cake solves this problem by adding a build script into source control, rather than configuring steps in a build server, meaning developers on different branches can make conflicting changes without impacting each other. When the build server runs, it simply has a single step which is to execute the Cake script from the branch it is on.

Cake Structure

A cake script is made of many steps which are chained together, each one performing a specific separate task such as restoring NuGet, building a solution, running unit tests or publishing artefacts. Steps are written using C# and can bring in NuGet packages to extend the functionality, so options are fairly limitless.

When the cake script first runs it parses the script and checks for errors, downloads any tools it needs, and then runs the script itself. A very simple example of how we use cake is available on our GitHub (https://github.com/CaternetClub/Zupa.Samples.Cake).

Spreading the Cake

As a team, we have already felt the benefits from using Cake, and rarely have any issues at build time. Other than some knowledge sharing and initial up-skilling, things have been relatively smooth and considering what it enables, we are certainly advocates.