Stage
A CI/CD stage is a logical phase of a pipeline, such as build, test, scan, or deploy, that groups jobs and must succeed before the next stage starts.
Understanding CI/CD Stages
What Is a Stage and How Does It Gate the Pipeline
A stage groups related jobs into one phase of delivery. Stages run in sequence, and jobs inside a stage can run in parallel. If any job in a stage fails, later stages do not run by default, which is what stops a failing test from reaching production. A stage only has value if it genuinely blocks.
Stages in GitLab CI
stages: - build - test - scan - deploy build-image: stage: build script: - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . unit-tests: stage: test script: - npm test lint: stage: test # runs in parallel with unit-tests script: - npm run lintStages in GitHub Actions
GitHub Actions has no stages keyword. You get the same effect by ordering jobs with needs.
jobs: build: runs-on: ubuntu-latest steps: - run: docker build . unit-test: needs: build runs-on: ubuntu-latest steps: - run: npm test lint: needs: build runs-on: ubuntu-latest steps: - run: npm run lint deploy: needs: [unit-test, lint] runs-on: ubuntu-latest steps: - run: ./deploy.shPractical Commands
gh run rerun 1234567890 --failedglab ci retry 1234567In a Jenkinsfile, wrap flaky steps in retry(3) { sh 'npm test' } for transient failures.
Troubleshooting
| Symptom | Check | What to look for |
|---|---|---|
| Stage skipped | Job conditions | if or rules excluding it |
| Stage hangs | Timeout settings | Process waiting for input |
| Parallel jobs conflict | Shared state | Same files or ports used |
TipName stages after purpose, such as Test or Scan, not tools, such as jest or trivy. Tools change, purposes do not.
RememberEvery stage is a gate. If a test stage may fail without blocking, it is decoration.
SecurityProduction deploy stages should require explicit approval through environment protection rules.
Common MistakeOne huge stage that builds, tests, scans, and deploys. Split concerns so failures are obvious and retries are targeted.
Frequently Asked Questions
What is the difference between a stage and a job?
A stage is a phase like build or test. A job is the unit of work inside it. Jobs in a stage can run in parallel, while stages run in order.
Can stages run in parallel?
Normally no, because each stage waits for the previous one. Features such as GitLab needs or GitHub needs let a job start as soon as its dependencies finish, which shortens pipelines.
How many stages should a pipeline have?
Only as many as there are genuine gates. Too few hides which phase failed, too many sequential stages slows the pipeline for no benefit.