Gitlab Pipeline – stages – What is stages in GitLab CI/CD?

DevOps

YOUR COSMETIC CARE STARTS HERE

Find the Best Cosmetic Hospitals

Trusted โ€ข Curated โ€ข Easy

Looking for the right place for a cosmetic procedure? Explore top cosmetic hospitals in one place and choose with confidence.

โ€œSmall steps lead to big changes โ€” today is a perfect day to begin.โ€

Explore Cosmetic Hospitals Compare hospitals, services & options quickly.

โœ“ Shortlist providers โ€ข โœ“ Review options โ€ข โœ“ Take the next step with confidence

Great! Letโ€™s go through a basic example of GitLab CI/CD pipeline YAML that demonstrates how the stages keyword is used.


๐Ÿ”ง What is stages in GitLab CI/CD?

The stages keyword defines the sequence of execution in your pipeline. Jobs are grouped under these stages, and GitLab runs the stages in order: one must complete successfully before the next begins.


โœ… Basic GitLab CI YAML Example

stages:
  - build
  - test
  - deploy

# Job in "build" stage
build-job:
  stage: build
  script:
    - echo "Compiling the app..."
    - echo "Build complete!"

# Job in "test" stage
test-job:
  stage: test
  script:
    - echo "Running unit tests..."
    - echo "All tests passed!"

# Job in "deploy" stage
deploy-job:
  stage: deploy
  script:
    - echo "Deploying the app..."
    - echo "Deployment successful!"
Code language: PHP (php)

๐Ÿ“˜ Explanation

๐Ÿ”น stages Section

stages:
  - build
  - test
  - deploy
  • This declares three sequential stages: build, test, and deploy.
  • GitLab will execute jobs in this order, waiting for all jobs in one stage to pass before moving to the next.

๐Ÿ”น Jobs and Their Assigned Stages

build-job:

build-job:
  stage: build
  script:
    - echo "Compiling the app..."
Code language: PHP (php)
  • This job is part of the build stage and will run first.

test-job:

test-job:
  stage: test
  script:
    - echo "Running unit tests..."
Code language: PHP (php)
  • This runs only after all build jobs succeed.

deploy-job:

deploy-job:
  stage: deploy
  script:
    - echo "Deploying the app..."
Code language: PHP (php)
  • This runs last, only if all test jobs succeed.

๐Ÿง  Key Notes

  • If a stage has multiple jobs, GitLab runs them in parallel (if runners are available).
  • If any job in a stage fails, subsequent stages are skipped.
  • You must explicitly assign stage: to every job (or it defaults to test if not defined).

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x