Build Servers

DevOps Ep. 4: Build Servers

For part 4 of our Getting Started with DevOps Series, I want to introduce you to Continuous Integration (CI): Making automatic builds of our newest code available to all team members.
To keep things simple, we will start with a simple build server, which can build a C# hello world project for macOS and linux, verifying your cross-platform compatibility.
Later tutorials will introduce pipelines covering automatic tests and deployments for offline applications as well as server applications.

Creating a Build Server

Before we get into the Bouncer CI setup, let’s get a simple Build server running ourselves.
For this tutorial we will create a quick .NET Core “hello world” on GitHub.

  1. Create a new GitHub Repository (here is mine)
  2. Clone your new repository to your computer
  3. Open a console and navigate to your repository
  4. run “dotnet new console
  5. commit and push

Choosing a Build Server

There are many good build servers available. All of them have similarities and will get most jobs done.

Travis CI is free to use for open source projects and feature rich.
So it looks like Travis CI is a great place to start.
We also use Travis CI for BrutalHack.Bouncer. You can see our build reports here: https://travis-ci.org/github/BrutalHack/Bouncer/builds

Choosing an Operating System

As developers prefer different operating systems, I suggest we embrace this instead of forcing all developers to use windows or linux.

As a result, your developers are able to use the operating system of their choice. Simply have your build server run the rarest operating system in your team.
Nobody is programming on linux? Then we should build on linux.
Nobody is coding on windows? Then we should build on windows.

Our goal here is to guarantee flexibility for our team and to guarantee that our product will also be more stable on the target system.

Getting Started with Travis CI

As mentioned earlier, we will be using Travis CI with GitHub. So let’s begin by setting up Travis CI! At first we have to follow the guide in the Travis CI Tutorial to authorize TravisCI as GitHub App:

Granting Travis CI build servers access to our Github Repositories
Granting Travis CI access to our GitHub Repositories

Next we create a simple .travis.yaml file in out repositories root:

language: csharp
# if your .sln file has a different name, change it here :)
solution: ci-example.csproj

This will build a C# solution from the ci-example.sln solution file with default settings.

  1. Commit
  2. Push
  3. Watch Travis CI build your project at https://travis-ci.com/
    (here is my build report)
Travis CI building our first commit with travis CI support

If you click on “View Config” in the screenshot above, you will see the default configuration using linux, specifically “xenial”.
The Travis CI linux documentation tells us, that this refers to Ubuntu 16.04 Xenial Xerus.

Cross-Platform Builds

Now let’s complete this tutorial by customizing our build config.
Specifically we want to verify our cross-platform compatibility.
As Travis CI does not support building C# projects on windows, we will only build on macOS and linux within this tutorial.

We can do this by introducing jobs in our .travis.yml file according to the Travis CI Multi OS documentation. Because our C# hello world project is created with .net core 3.1, we must define this version as described in the Travis CI C# Documentation.

language: csharp
# if your .sln/.csproj file has a different name, change it here :)
solution: ci-example.csproj

# Travis CI jobs to run multiple builds
jobs:
  include:
    # linux build with Ubuntu 18.04 "Bionic Beaver"
    # (https://docs.travis-ci.com/user/reference/linux/
    - os: linux 
      dist: bionic
      # .Net Core version 3.1.302 
      # (https://dotnet.microsoft.com/download/dotnet-core/3.1)
      dotnet: 3.1.302
    # macOS build with "xcode12" image running macOS 10.15.5 with Xcode 12
    # (https://docs.travis-ci.com/user/reference/osx/)
    - os: osx
      osx_image: xcode12
      # .Net Core version 3.1.302 
      # (https://dotnet.microsoft.com/download/dotnet-core/3.1)
      dotnet: 3.1.302

After commiting and pushing our new .travis.yml, you will see the new build starting with two build jobs instead of one.
The following screenshot displays my build with the two build jobs.
You can see the full build report here at Travis CI:

Successful linux & macOS builds

Conclusion

Now we know how to setup automated builds, which can verify, that our code works independently of our development machine and cross-platform. Our next episodes will extend our build server to run automated tests and automatically upload releases to GitHub.

Until then, you can reach out to me on Twitter or the BrutalHack Discord Server for questions. I also recommend some further research in the excellent Travis CI documentation.