Basic

The parts of a pipeline

A pipeline is made of stages. Each stage is a step that runs in order. The most common stages are install, test, build, and deploy.

What you will see

All green. Code reaches production.

About 1 min of reading

Quick check

Before this new lesson, one small question about the lesson you just finished. Recall it, do not look it up.

Try It

A pipeline is made of stages that run in order. I walk through a four-step pipeline, stop as soon as a stage turns red, then check whether every stage is green to decide whether the code can ship.

1

The most common stages are install, test, build, and deploy, and they run one after another. I loop through the stages and print each one as it runs.

stages = ["install", "test", "build", "deploy"] for s in stages: print(f"Running stage: {s}")

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Running stage: install Running stage: test Running stage: build Running stage: deploy
Each stage waits for the one before it to finish. If any stage fails, the rest are skipped.
2

As soon as a stage turns red, the pipeline stops and the later stages never run. I run the steps one by one, fail the test step, and print that the build step is skipped.

stages = ["npm install", "npm test", "npm run build"] for i, stage in enumerate(stages): print(f"Running: {stage}") if i == 1: print("Stage failed. Pipeline stopped.") print(f"Skipped: {stages[i+1]}") break

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Running: npm install Running: npm test Stage failed. Pipeline stopped. Skipped: npm run build
The later stages are skipped on failure, so the log always shows exactly which step broke.
3

Every stage reports green or red, and the pipeline is only done when all four are green. I set each stage to green and print that the code reaches production only when they all pass.

statuses = {"install": "green", "test": "green", "build": "green", "deploy": "green"} if all(v == "green" for v in statuses.values()): print("All green. Code reaches production.") else: print("Red found. Deploy blocked.")

Before you run it, say out loud what it will print. Then open the answer.

What it prints
All green. Code reaches production.
A passing stage shows green and a failing one shows red. A pipeline is only done when every stage is green.

Put it in order

Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.

Data Flow

A pipeline runs install, test, build, and deploy in order, stopping on the first failure.
1 Install dependencies
↓
2 Run tests
↓
3 Build the app
↓
4 Deploy it
Why this works
Stages run in order

Each stage waits for the one before it to finish. If any stage fails, the rest are skipped.

Red and green

A passing stage shows green. A failing stage shows red. A pipeline is only done when every stage is green.

Examples

A four-step pipeline

# A tiny pipeline
- install: pip install -r requirements.txt
- test: pytest
- build: make package
- deploy: ship it

If the test step fails, the pipeline stops. The build and deploy steps never run. This keeps bad code from shipping.

When a stage fails

jobs:
  build:
    steps:
      - run: npm install
      - run: npm test    # <-- this fails
      - run: npm run build  # never reached

As soon as a stage turns red, the pipeline stops. The later stages are skipped. You see exactly which step broke.

Green means go

Every stage reports its own status: green for pass, red for fail.

  • install brings in dependencies.
  • test runs the automated checks.
  • build packages the app.
  • deploy releases it to users.

Only when all four are green does the code reach production.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← What is CI/CD?
Previous Lesson
What is CI/CD?
Next Lesson
Running your first pipeline
Running your first pipeline →