DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

Homework Lab — Build Your Own CI Pipeline

Goal

Each student creates their own website repository and builds a CI pipeline that performs:

Developer
   ↓
Feature Branch
   ↓
Push
   ↓
Pull Request
   ↓
CI
   ↓
Checkout
   ↓
Lint
   ↓
Test
   ↓
Security
   ↓
Build
   ↓
PASS ✓
   ↓
Merge
Enter fullscreen mode Exit fullscreen mode

For this homework, the Lint, Test, Security, Build stages can be simple educational checks. They don't need SonarQube, Trivy, or Docker yet.


Part 1 — Create the project

mkdir ci-homework
cd ci-homework

git init
git branch -M main

touch index.html
Enter fullscreen mode Exit fullscreen mode

Add:

<!DOCTYPE html>
<html>
<head>
    <title>JumpToTech CI Homework</title>
</head>

<body>
    <h1>My DevOps CI Project</h1>
    <p>Student: YOUR NAME</p>
    <p>I am learning Continuous Integration.</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Then:

git status
git add .
git commit -m "Create website"
Enter fullscreen mode Exit fullscreen mode

Create an empty GitHub repository named:

ci-homework
Enter fullscreen mode Exit fullscreen mode

Connect it:

git remote add origin YOUR-REPOSITORY-URL
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Part 2 — Work like a real Developer

Do not build the CI directly on main.

git switch -c feature-ci
Enter fullscreen mode Exit fullscreen mode

Create:

mkdir -p .github/workflows
nano .github/workflows/ci.yml
Enter fullscreen mode Exit fullscreen mode

Part 3 — Create the CI Pipeline

Use:

name: Student CI Pipeline

on:
  push:
  pull_request:

jobs:
  ci:
    runs-on: ubuntu-latest

    steps:

      - name: Checkout Code
        uses: actions/checkout@v4

      - name: Lint
        run: |
          echo "Running Lint..."
          test -s index.html

      - name: Test
        run: |
          echo "Running Tests..."
          grep "DevOps" index.html

      - name: Security Check
        run: |
          echo "Running Security Check..."
          if grep -qi "password" index.html; then
            echo "Security check failed"
            exit 1
          fi
          echo "Security check passed"

      - name: Build
        run: |
          echo "Running Build..."
          mkdir -p build
          cp index.html build/index.html
          test -f build/index.html

      - name: CI Complete
        run: echo "CI PIPELINE PASSED"
Enter fullscreen mode Exit fullscreen mode

Tell students:

These are simplified educational checks. The purpose is to understand pipeline structure and failure behavior before we introduce professional Lint, Test, Security and Build tools.


Part 4 — Understand every stage

They must be able to explain:

Checkout
↓
Get repository code onto Runner

Lint
↓
Basic file/code validation

Test
↓
Check expected content/behavior

Security
↓
Look for an intentionally unsafe pattern

Build
↓
Produce build output
Enter fullscreen mode Exit fullscreen mode

They should not receive full credit simply because everything is green.

They need to explain what each stage does.


Part 5 — Commit and Push

git status
git diff

git add .
git commit -m "Add CI pipeline"

git push -u origin feature-ci
Enter fullscreen mode Exit fullscreen mode

Then create:

feature-ci
     ↓
Pull Request
     ↓
main
Enter fullscreen mode Exit fullscreen mode

Do not merge yet.

First check GitHub Actions.

Goal:

✓ Checkout
✓ Lint
✓ Test
✓ Security Check
✓ Build
✓ CI Complete
Enter fullscreen mode Exit fullscreen mode

Part 6 — BREAK the Pipeline

This part is mandatory.

Change:

<p>I am learning Continuous Integration.</p>
Enter fullscreen mode Exit fullscreen mode

and remove the word:

DevOps
Enter fullscreen mode Exit fullscreen mode

from the entire index.html.

Commit:

git add .
git commit -m "Test CI failure"
git push
Enter fullscreen mode Exit fullscreen mode

Because CI contains:

grep "DevOps" index.html
Enter fullscreen mode Exit fullscreen mode

the Test stage should fail:

✓ Checkout
✓ Lint
✗ Test
- Security
- Build
Enter fullscreen mode Exit fullscreen mode

Students must open the failed workflow and read the logs.


Part 7 — Troubleshoot

They should answer:

Which Job failed?

Which Step failed?

Which command failed?

Why did it fail?

What should I change?
Enter fullscreen mode Exit fullscreen mode

Then put DevOps back into index.html.

git add .
git commit -m "Fix failed CI test"
git push
Enter fullscreen mode Exit fullscreen mode

Now:

FAIL ✗
   ↓
Read Logs
   ↓
Find Root Cause
   ↓
Fix
   ↓
Commit
   ↓
Push
   ↓
PASS ✓
Enter fullscreen mode Exit fullscreen mode

Part 8 — Security Failure Challenge

Now intentionally add:

<p>password=123456</p>
Enter fullscreen mode Exit fullscreen mode

Commit and push:

git add .
git commit -m "Test security check"
git push
Enter fullscreen mode Exit fullscreen mode

This time students should see:

✓ Checkout
✓ Lint
✓ Test
✗ Security Check
Enter fullscreen mode Exit fullscreen mode

Ask them:

Why didn't Build run?

Because an earlier required step failed.

Then remove:

password=123456
Enter fullscreen mode Exit fullscreen mode

Commit and push again.

Goal:

✓ Checkout
✓ Lint
✓ Test
✓ Security Check
✓ Build
✓ CI Complete
Enter fullscreen mode Exit fullscreen mode

Part 9 — Merge only after Green

Now return to the Pull Request.

Only when CI is:

✓ GREEN
Enter fullscreen mode Exit fullscreen mode

merge:

feature-ci
   ↓
PR
   ↓
CI ✓
   ↓
Review
   ↓
Merge
   ↓
main
Enter fullscreen mode Exit fullscreen mode

Then locally:

git switch main
git pull origin main
Enter fullscreen mode Exit fullscreen mode

Check:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

What Students Must Submit

Send me:

  1. GitHub repository link
  2. Screenshot of Pull Request
  3. Screenshot of successful green CI
  4. Screenshot of failed Test
  5. Screenshot showing the Test error/log
  6. Screenshot of failed Security Check
  7. Screenshot of final successful pipeline
  8. Screenshot showing the merged PR

And prepare to explain Monday:

What is CI?
What is a Pipeline?
What is a Trigger?
What is a Runner?
What does Checkout do?
What is a Job?
What is a Step?
What is Lint?
What is Test?
What is Security Check?
What is Build?
Why did your Test fail?
Why did your Security Check fail?
How did you troubleshoot them?
Why should CI pass before Merge?
Enter fullscreen mode Exit fullscreen mode

The rule for the homework

Do not just send me a green check. Be ready to explain how you made it RED, how you found the problem, how you fixed it, and how you made it GREEN again.

Top comments (0)