Module 5 · Project 05 · Build a Complete CI/CD Pipeline · Lesson 19 of 48
Environments, approvals, versions and rollback
Protect production with environments and approval gates, version releases with semantic versioning, notify the team, and roll back automatically.
In this lesson · about 25 minutes
- Use GitHub environments with required reviewers and their own secrets
- Version releases with semantic versioning and Git tags
- Design an automatic rollback on a failed health check
Environments and approval gates
In GitHub, an environment (such as staging or production) can have its own secrets and protection rules. Set required reviewers on production, and any job with environment: production pauses until one of them approves. You can also limit production deploys to the main branch.
Semantic versioning
Versions like 1.4.0 are MAJOR.MINOR.PATCH:
- PATCH (1.4.0 → 1.4.1): bug fixes only.
- MINOR (1.4.1 → 1.5.0): new features that don't break anything.
- MAJOR (1.5.0 → 2.0.0): breaking changes.
Create a Git tag such as v1.4.0 and let a workflow triggered by on: push: tags: ['v*'] do the release, so the version, the Git tag and the image tag always match.
Rollback
Every deploy needs a way back. Because each release is an immutable image tag, rolling back is just deploying the previous tag. Automate it: after deploying, check health for a minute; if it fails, redeploy the last good tag and mark the run as failed:
PREV=$(cat /srv/notes/current-tag) # remember what was running
./deploy.sh production "$NEW_TAG"
if ! curl -fsS --retry 10 --retry-delay 6 https://notes.example/health; then
echo "Health check failed, rolling back to $PREV"
./deploy.sh production "$PREV"
exit 1 # the pipeline goes red
fi
echo "$NEW_TAG" > /srv/notes/current-tag
Finally, notify: post "v1.4.0 deployed to production by Ana" or "rollback to v1.3.2" in the team channel, so everyone knows what changed and when. Project 12 takes this further with rolling, blue-green and canary releases.
Watch out: database changes
Rolling back code is easy; rolling back a database isn't. Make schema changes backwards-compatible (add a column first, start using it in a later release, remove the old one later still) so the previous version still works if you roll back.
Whiteboard · watch and try
Which version number?
Press Play. The current release is 2.3.4.
Tip: press Pause, then use the pen to work along on the board. Space plays and pauses; Ctrl+Z undoes your last mark.
Decision scenario
Friday-afternoon release
You run releases for the notes app. Version 1.5.0 passed staging and is waiting at the production approval gate.
It's 4:45 pm on Friday. The release adds a database column and changes the export feature. Monitoring is set up, but only two people know how to roll back and one is on holiday.
What do you recommend?
0 of 3 options explored. Try the others to see how each would play out.
Check your understanding0 of 3 correct
Key terms
Say the meaning to yourself, then tap a card to check.
Quiz score: 0 of 3
Written by Noviq Academy in its own words. The labs are simulations: no real servers are touched. When you build the projects yourself, use a practice virtual machine or a free-tier cloud account you control, watch your cloud spending, and never run cleanup or delete commands on a machine you care about. Tool names belong to their owners; versions and output are shown for learning and may differ slightly from yours. Read-aloud and the whiteboard voice use your device's built-in voices.