Continuous Integration (CI)
Continuous integration means merging changes into the shared main branch often and building and testing each of them automatically. That way, integration errors show up at once, not weeks later.
Continuous integration (CI) means merging changes into the shared main branch frequently and building and testing each of them automatically. Errors in how the parts work together show up at once, not after weeks of separate work.
What makes CI
Microsoft describes CI as building and testing automatically on every commit. A commit to the main branch triggers the build, which builds, tests, and checks the whole. Work happens on short-lived branches, a pull request is sent, and after approval it is merged. Three things make up the core:
- A neutral machine: The build runs on a clean machine that knows only the repository. Whatever only works on your computer shows up there.
- Always the same steps: No person decides whether there is testing today.
- A clear verdict: green or red.
The goal is a main branch that builds at any time and whose tests pass.
Tools in the Microsoft world
For CI, Microsoft names GitHub Actions and Azure Pipelines (part of Azure DevOps). Both read a YAML file from the repository that states the event, the machine, and the steps. For .NET, the steps are essentially two commands:
dotnet build --configuration Release
dotnet test --configuration Release --no-build
A red test ends the run with an error code. If the check is set as required in the repository, it blocks the merge.
An example from the Kladde
Every pull request of the Kladde runs a check that builds, checks the formatting, and runs all test projects. Whatever only runs on your own computer, for example because the language setting there is German, shows up on the pipeline's neutral machine.
How it differs
- CI and CD: CI builds and checks, continuous deployment delivers. CI is the precondition.
- CI and tests: CI runs tests, but it does not replace them. Without unit tests, a pipeline only checks whether the code compiles.
- CI and DevOps: CI is a practice of DevOps.
- Flaky tests (sometimes green, sometimes red without a code change) undermine trust in CI and should be fixed rather than rerun.
In the course
You write CI yourself in K3, module 3.7: Continuous integration with GitHub Actions, then Azure Pipelines and Tests in the build. How tests get into every pull request is already shown in K2, module 2.7, lesson All tests in every pull request.
Further reading on the blog
- Software tests: types and how to use them in a project
- Release planning: planning further development in a structured way
Sources
- Microsoft Learn, Use continuous integration: https://learn.microsoft.com/devops/develop/what-is-continuous-integration
- Microsoft Learn, What is Azure Pipelines?: https://learn.microsoft.com/azure/devops/pipelines/get-started/what-is-azure-pipelines?view=azure-devops