# Builds, Artifacts and Environments

Course: [CI/CD](https://www.devtutorials.ai/learn/cicd) · Section: Start Here
Source: https://www.devtutorials.ai/learn/cicd/start-here/builds-artifacts-environments

> What a build makes, why the pipeline saves it as a named artifact, and how dev, staging and production differ. The three words every later lesson uses.

## Three Words You Need First

Every pipeline talks about three things:

- **Build:** making your app ready to run.
- **Artifact:** the ready app, saved with a name.
- **Environment:** a place where the app runs.

The next lessons use these words all the time.

**Simple lesson:** a pipeline builds the app, saves it as an artifact, and puts it in an environment.

### A Real-World Example

Think about a tailor making a school uniform.

- **Cloth and a pattern** = your source code.
- **Cutting and stitching** = the build.
- **The finished uniform, in a bag with your name** = the artifact.
- **Trial room, then school** = environments.

Now notice two rules:

- You try the uniform in the trial room before school.
- You wear the **same** uniform to school. Not a new one stitched again.

**Simple lesson:** build once, check it, then use the same thing everywhere.

## Build

**Build** = turning source code into files a computer can run.

- You write code that people can read.
- A browser or server needs a different, packed form.
- A build tool does that work.

| Your app | Build command | Output folder |
|---|---|---|
| React + TypeScript | `npm run build` | `dist/` |
| ASP.NET Core | `dotnet publish -c Release -o out` | `out/` |

Press **Build** below and watch the files change.

- **Left side:** files you write and read.
- **Right side:** files the build makes. You never edit them by hand.
- **The build needs packages first.** That is why install comes before build.

**Simple lesson:** source goes in, ready-to-run files come out.

### Try It: Find the Build Output

- `ls` = a command that lists the files in a folder.
- It proves the build really made the output.

### A Build Also Catches Mistakes

- To build, the tool must understand every line.
- A wrong type or a missing file stops the build.
- So a build is also the first check.

**Simple lesson:** if the build fails, nothing after it runs. It is your first safety net.

## Artifact

**Artifact** = the build output, saved with a name, so later steps can use it.

- The runner is thrown away after each job.
- Anything you do not save is lost.
- So the pipeline saves the output as an artifact.

A good artifact name says which build it came from:

- `web-3f9c2ab` = built from commit 3f9c2ab.
- `web-20261116.42` = build number 42 on 16 Nov 2026.

**Real tools vs this lab:** GitHub Actions and Azure Pipelines both store artifacts for you. GitHub keeps them for 90 days by default. In this lab, saving and loading happen inside the simulator.

**Simple lesson:** an artifact is the "uniform in a bag with your name". Same bag, every place.

## Environment

**Environment** = one copy of your app, running somewhere, for some people.

Most teams have three:

- **Development:** on your laptop. Only you see it.
- **Staging:** a test copy online. The team checks it.
- **Production:** the real site. Real customers use it.

Pick an environment and a person below.

- **Staging** should look like production, but with test data.
- **Production** is where mistakes cost real money.
- That is why production gets the most checks.

Never test on production first. A bug there hits real customers. Always go through staging.

**Simple lesson:** each environment is a safer place to fail than the next one.

## Putting It Together

This is the whole course in one line:

- **Build** the code.
- **Test** it.
- **Save** the artifact.
- **Deploy** that artifact to staging.
- **Check** staging.
- **Deploy** the same artifact to production.

### Fix It: Install Before Build

- The build needs packages from the install step.
- Steps run top to bottom. Order matters.

**Simple lesson:** build needs install. Deploy needs an artifact. Each step needs the one before it.

1. In your starter repo, run the build on your laptop: `npm run build` (React) or `dotnet publish Shop -c Release -o out` (.NET).
2. Open the `dist/` or `out/` folder.

**What you should see:** a few ready-to-run files. That folder is what a build makes, and what the pipeline later packs into an image.

## Quick Check

## Cheat Sheet

| Word | Means | React + TypeScript | ASP.NET Core |
|---|---|---|---|
| Build | Make the app ready to run | `npm run build` | `dotnet publish -c Release -o out` |
| Output | What the build makes | `dist/` | `out/` |
| Artifact | Saved, named output | `web-3f9c2ab` | `web-3f9c2ab` |
| Environment | Where the app runs | dev, staging, production | dev, staging, production |

## Common mistakes

| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| Build before install | The tools are already there | The runner starts empty | "tsc: not found" or "assets file not found" |
| Not saving the output | The files stay on the runner | Runners are deleted after each job | The deploy job has nothing to deploy |
| Building again for production | A new build is the same | It may pick up different packages | Production runs code nobody tested |
| Testing on production | It is the real thing, so test there | Staging is for testing | Real customers see the bug |
| Editing files in `dist/` or `out/` | It is quicker | They are made by the build | Your change disappears next build |

When a deploy goes wrong, ask: which artifact is running? A good name like `web-3f9c2ab` answers that in one second.

## What to Remember

- Build = make it runnable.
- Artifact = the runnable thing, saved with a name.
- Environment = where it runs: dev, staging, production.
- Install, then build, then save.
- Build once. Deploy that same artifact everywhere.

## Exercises

Next: **Your First Pipeline**
