CI/CD introduction
On this page 8 topics
Overview
Topics
- GitHub Actions or GitLab CI
- build/test pipeline
- artifacts
Learn first
3 h of practice (estimate)
Learning outcomes
- Explain continuous integration, delivery, and deployment.
- Write a GitHub Actions workflow that builds, runs all tests (including Testcontainers), and caches dependencies.
- Publish build artifacts (JAR, container image) to a registry with version tags.
- Protect
mainwith required checks.
Lessons
Lab and exercises
Lab
JNR-051-LAB1 · Shop pipeline
Outcomes: 1–4 · Time: ~3 h Every PR runs the full suite (including Testcontainers) with caching; merges to main publish a tagged image; main is protected with required checks. Acceptance: a PR with a failing test cannot be merged.
Exercises (assessment: fix a broken workflow)
| ID | Outcome | Task |
|---|---|---|
| JNR-051-EX01 | 1 | Explain CI, continuous delivery, and continuous deployment in one sentence each, with a Shop example. |
| JNR-051-EX02 | 2 | Write a workflow that checks out, sets up Java 21 with Maven cache, and runs ./mvnw -B verify on pull requests. |
| JNR-051-EX03 | 2 | Confirm Testcontainers tests run in the workflow and find the test count in the log. |
| JNR-051-EX04 | 3 | Add a job that builds the image and pushes it to ghcr.io tagged with the commit SHA on pushes to main. |
| JNR-051-EX05 | 4 | Configure branch protection requiring a PR, one review, and the build check. |
| JNR-051-EX06 | 2 | Given a broken workflow (wrong indentation, -DskipTests, missing permissions), find and fix each defect. |
Show solutions
- EX01 CI: merge often and test automatically. Delivery: every green build is releasable, a human approves. Deployment: every green build goes live automatically.
- EX02
on: pull_request; stepsactions/checkout,actions/setup-javawithcache: maven,run: ./mvnw -B verify. - EX03 Runners have Docker; the Surefire/Failsafe summary shows "Tests run: N"; N must be above zero.
- EX04
ifthe event is a push tomain;permissions: packages: write;docker/login-actionwithGITHUB_TOKEN;docker/build-push-actionwithtags: ghcr.io/${{ github.repository }}:${{ github.sha }}. - EX05 Settings, Branches (or Rulesets): require pull request, 1 approval, status check
build, block force pushes. - EX06 Fix YAML indentation, remove
-DskipTests, addpermissions: packages: writefor pushing images. - Common mistakes (secrets printed in logs, zero tests run) are checked in the EX06 review.
Quiz
Outcomes: O1 CI/CD concepts · O2 workflows · O3 artifacts and images · O4 branch protection.
A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.
Practical part
Six exercises JNR-051-EX01 to EX06 plus the lab; for the assessment, fix a broken workflow. Pass: quiz 8/10, at least five exercises correct, and a failing-test PR blocked from merging.
Common mistakes
Secrets printed in logs; pipelines that pass with zero tests run.
Assessment
Fix a broken workflow.
Career relevance
CI/CD advanced (MID-055).