Skip to content

DevOps Operations / Continuous integration · Step 1 of 7

Lesson: Continuous IntegrationSwitch
← DevOps Operations

Delivery and containers

Continuous Integration

What continuous integration is and what a first automated workflow looks like.

Imagine two people change the same project for a week without sharing. Joining their work is painful, and bugs hide in the join. Continuous integration (CI) is the habit of merging small changes often and checking each one automatically.

The loop

A typical CI loop looks like this:

  1. You push a commit or open a pull request.
  2. A server takes a clean copy of the code.
  3. It builds the project and runs the tests.
  4. It reports pass or fail next to your change.

The value comes from fast feedback. If a test fails minutes after a small commit, there are only a few lines to suspect.

A clean machine

CI usually runs on a fresh environment, not your laptop. That catches the classic "works on my machine" problem: a file you forgot to commit, or a tool you installed long ago and never wrote down.

CI is only as good as its checks. A green result means the checks you wrote passed. It does not prove the software has no bugs.

A first workflow

Many tools provide CI. This topic uses GitHub Actions for its examples. You describe a workflow in a YAML file inside .github/workflows/ in your repository.

yaml
# .github/workflows/ci.yml
name: CI
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: ./test.sh

Here on says when to run, jobs says what to do, runs-on chooses the machine and steps lists the actions in order. The checkout step copies your repository onto the machine. Without it, your files would not be there.

The same commands locally

Keep the real work in scripts that you can also run yourself:

bash
#!/bin/sh
set -e
echo "Running tests"
test "$(echo 2+3 | bc)" = "5"
echo "OK"
Running tests
OK

set -e makes the script stop at a failing command, in most situations. A CI step whose command exits with a status other than 0 fails. That one rule connects your scripts to the pass or fail mark. This example needs bc to be installed.

Try it

Save the script as test.sh, run chmod +x test.sh, then ./test.sh; echo $?. Change 5 to 6 and run it again. The exit status changes from 0 to a nonzero number. Commit the file with the executable bit so the workflow can run it. The official GitHub Actions documentation covers the workflow format in full, and the permissions lab lets you practise chmod.

Check your understanding

Continuous Integration

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.