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.
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.
- Create a new GitHub Repository (here is mine)
- Clone your new repository to your computer
- Open a console and navigate to your repository
- run “
dotnet new console“
- commit and push
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
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.
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:
Next we create a simple .travis.yaml file in out repositories root:
<!-- HTML generated using hilite.me -->
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.
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.
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.
<!-- HTML generated using hilite.me -->
language: csharp# if your .sln/.csproj file has a different name, change it here :)solution: ci-example.csproj# Travis CI jobs to run multiple buildsjobs: 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:
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.