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

DevOps

MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare

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).

Subscribe
Notify of
guest

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

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x