Over a million developers have joined DZone.

Abstract From Your CI. Use Cake!

DZone's Guide to

Abstract From Your CI. Use Cake!

Cake is a tool for C# allows you to speed up your development in an agile way by allowing you to abstract from your CI server. Sounds tasty!

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

Here at Coolblue, we can choose our tools from a range of technologies. A while ago, our team started moving from Microsoft MSTest to xUnit.

Although the code change was fairly simple, the build pipeline was tied with the MSTest framework, ignoring the xUnit tests. Between the requests to the deployment team to alter the team's deployment pipelines, Nathan challenged us to use Cake.

What Is Cake?

Image source.

Although I'm a cake monster, "Cake (C# Make) is a cross-platform build automation system with a C# DSL to do things like compiling code, copy files/folders, running unit tests, compress files and build NuGet packages (source)."

Great, this is the tool that was missing, allowing us to abstract from our CI server, speeding our development (and in the end, that is Agile)!

The Roller-Coaster

Cake allows us to build our project in many different ways with a syntax that is our bread and butter (C#). The platform is open-source, meaning that we can fix any bug, or contribute with a module to increase the ecosystem.

During my spare time, I started playing around with Cake in a pet project. The pet project is built using .NET Core 2.0, and the ultimate goal was to build the project in AppVeyor and TravisCI. The build steps were:

  1. Ensure the non-solution folders exists (for example, artifacts folder).
  2. Clean the solution.
  3. Restore the NuGet packages.
  4. Apply the Semantic Versioning.
  5. Build the solution.
  6. Run the tests.

As a bonus, it should be able to:

  1. Package and push a NuGet package.
  2. Create and push a Docker container.

Cake offers support to all these steps, either out-of-the-box feature or as a module offered by the community.

The development was simplified since the operations to build & test my project was the same that the build server would execute. It avoids the old developer excuse "it works on my machine," since the developer machine has the same software that the build server (during the development I face this problem with AppVeyor. The solution was published here).

A Plethora of Opportunities

This approach decreased the time to configure two different CI servers since it supports the executing of the scripts in Windows, Linux, and MacOS.

However, the opportunities are endless. In an enterprise environment, the software is a complex web of services and other moving parts; a team needs to be able to add a feature, testing & shipping it quickly; at the same time assuring the business that is working as expected, and more important, it doesn't introduce any regression bugs.

Using Cake, we can setup the script to deploy the necessary components on our development machines, running the tests to assure that everything works before we push our changes. This level of automation and abstraction also enables the developers to focus on delivering value (coding a new feature), rather than spending time configuring and deploying (manually) all the components to run the tests. Raise your hand who was in this situation. Yeah, every developer. 

The Final Result

After a few hours around the script, both AppVeyor and TravisCI can execute it, predictably, as I do in my development environment. You can view a sample of the build logs here and here.

Within our team, we start to move towards this direction. All the new projects are bootstrapped with a basic Cake script (Clean, Restore, Build, Test and Create NuGet package), but the team iteratively adapts it to our development needs. In the end, a development team should be proud of the software delivered, because it improves the business, but also the team was able to use the time is an effective way.

And for Other Languages/Frameworks?

The same concept exists in other languages/frameworks. As a short list, we have:

Be aware that this is a short list. Out there exists other build platforms that allow you to abstract from your CI server.

The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

devops ,continuous integration ,c#

Published at DZone with permission of João Rosa, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}