Lesson 2 of 4 · Free to read
Exercises
Exercises — CI/CD: pipelines, environments, and AI-generated workflows
Watch & learn
Course video
Keep a prompt log while you work. Speed without a trail is not a skill — it is luck.
How to use this file
- All exercises use
code-examples/python/pipeline_lab/unless noted. - AI prompts go in
PROMPTS.md. - Every workflow you write must pass the AI-pipeline checklist.
Exercise 1 — Write a minimal CI workflow by hand
Goal: write a GH Actions workflow from scratch that installs deps and runs pytest for pipeline_lab/. No AI for this one.
Time: 25 minutes
Level: foundational
Modules touched: [11-ci-cd]
Setup
- Fork the cohort lab repo (or work in
code-examples/python/pipeline_lab/). - Make sure
.github/workflows/exists.
Steps
- Create
.github/workflows/ci.yml. - Trigger on
pushandpull_request. - One job,
ubuntu-24.04, Python 3.11. - Install deps (
pip install -e ".[dev]"). - Run
pytest. - Push, watch it run.
Success criteria
- Workflow runs green on
main. - Job uses pinned action versions (
@v4). - Runner is pinned (
ubuntu-24.04, notubuntu-latest).
AI prompt hints
- (None for this one — the point is to internalise the YAML.)
Solution sketch
A 15-line YAML file. Most learners will reach for ubuntu-latest; the pinning rule is the catch.
Stretch
- Add a
cachestep for pip wheels.
Exercise 2 — Add the test report as an artifact
Goal: extend Exercise 1 so pytest produces a JUnit XML and the workflow uploads it as an artifact. Time: 20 minutes Level: foundational Modules touched: [11-ci-cd]
Setup
- Same as Exercise 1.
Steps
- Add
pytest --junitxml=report.xml. - Add a
actions/upload-artifact@v4step that uploadsreport.xml. - Make
if: always()so it uploads even on failure. - Push, verify the artifact appears in the run UI.
Success criteria
- Artifact
report.xmlavailable from the run page. - The upload step runs even when pytest fails.
AI prompt hints
- "Ask Cursor: 'Add a JUnit XML upload step to this workflow that runs even on failure. Output a diff only.'"
Solution sketch
Two steps added. The if: always() is the easy-to-miss flag.
Stretch
- Add a
actions/upload-artifact@v4for any coverage report.
Exercise 3 — Generate a full pipeline with AI and critique it
Goal: prompt Cursor for a full pipeline (build → test → security → package → deploy to staging) and apply the AI-pipeline checklist. Time: 80 minutes Level: intermediate Modules touched: [11-ci-cd, 02-ai-assisted-development, 15-security-and-supply-chain]
Setup
- Work in
pipeline_lab/. ReadCHECKLIST.mdbefore prompting.
Steps
- Prompt Cursor for the full pipeline. Use the Specify pattern; include the stages explicitly.
- Open the generated YAML alongside
CHECKLIST.md. - Score it: how many items pass / fail / unclear?
- Hand-edit to fix every failing item. Log each edit in
PROMPTS.mdwith the reasoning. - Push. If the deploy step needs cloud credentials you don't have, mark it
if: falseand explain in a comment.
Success criteria
- Pipeline runs (deploy can be no-op).
- All checklist items pass.
PROMPTS.mdhas ≥1 entry per checklist failure with the AI's original output, your fix, and why.
AI prompt hints
- Specify: "Generate a GH Actions workflow for a FastAPI app. Stages: build, test, security (Trivy + secret scan), package (multi-stage Docker, sign with Cosign), deploy to staging on push to main with manual approval. Pin all actions to a specific tag. Use the
stagingenvironment for secrets." - Critique: "Here's the workflow. List 5 things a senior reviewer would flag. Reference my CHECKLIST.md."
Solution sketch
Common AI misses: @main actions, missing concurrency, secrets in plain env, missing artifact upload, no gate. Strong learners catch ≥5 and document each.
Stretch
- Re-prompt with the checklist attached and compare to round-1 output.
Exercise 4 — Add an environment gate
Goal: add a deploy-prod job that requires manual approval, runs only after deploy-staging, and pulls secrets from the prod environment.
Time: 35 minutes
Level: intermediate
Modules touched: [11-ci-cd]
Setup
- In your fork's GitHub Settings → Environments, create
stagingandprod. Onprod, require yourself as a reviewer.
Steps
- Add
environment: prodto thedeploy-prodjob. - Add
needs: deploy-staging. - Add
if: github.ref == 'refs/heads/main'. - Push and watch the run pause for approval.
- Approve via the GitHub UI; verify it proceeds.
Success criteria
- The run pauses at
deploy-produntil approved. - Approval shows your name in the timeline.
AI prompt hints
- "Ask Cursor: 'Add a manual-approval deploy-prod job to this workflow. Reference the prod environment. Output a diff only.'"
Solution sketch
The pause is the demonstration. Many learners have never seen a CI workflow wait on a human.
Stretch
- Add a wait timer of 5 minutes after staging deploy before prod is allowed.
Exercise 5 — Debug a deliberately broken pipeline (advanced)
Goal: open the planted-broken workflow in code-examples/python/pipeline_lab/.github/workflows/broken.yml and diagnose all 3 issues using logs only (no AI for diagnosis; AI allowed for fixes).
Time: 45 minutes
Level: advanced
Modules touched: [11-ci-cd]
Setup
- Push the planted broken workflow to your fork. Confirm it fails.
Steps
- Open the failed run. Read the logs.
- For each of the 3 failures, write in
DIAGNOSIS.md: stage, symptom, root cause, fix. - Apply the fixes (AI allowed; log every prompt in
PROMPTS.md). - Push, verify green.
Success criteria
DIAGNOSIS.mdlists 3 issues with stage / symptom / root cause / fix.- Workflow runs green after the fixes.
AI prompt hints
- Once diagnosed: "Here's the failing step. Fix the underlying issue without changing the test logic. Output a diff only."
Solution sketch
Planted issues include: missing actions/checkout, wrong Python version pin (mismatch with requires-python), secret referenced but not set. The discipline is the diagnosis step — many learners skip to AI and "fix" the wrong thing.
Stretch
- Write a
rerun-failedscript:gh run rerun <run-id> --failed. When is this safe vs unsafe?