Module 3 Lesson 1: Hello World Pipeline
·DevOps

Module 3 Lesson 1: Hello World Pipeline

Your first automated build. Follow a step-by-step guide to creating, committing, and running your very first GitLab CI/CD pipeline.

Module 3 Lesson 1: Hello World Pipeline

It's time to stop talking and start building. In this lesson, we will create a "Minimal Viable Pipeline."

1. Prerequisites

  • A GitLab account (GitLab.com is fine).
  • A new, empty project.

2. Step 1: Create the file

In your project's root directory, create a new file named exactly .gitlab-ci.yml.

# Define our simple stages
stages:
  - build
  - test

# Our first job
say-hello:
  stage: build
  script:
    - echo "Hello from GitLab CI!"
    - date

# Our second job
run-test:
  stage: test
  script:
    - echo "Running simulation..."
    - exit 0 # 0 means success

3. Step 2: Commit and Push

Push this file to your main branch.

git add .gitlab-ci.yml
git commit -m "Add first pipeline"
git push origin main

4. Step 3: Watch it run

  1. Go to your GitLab project sidebar.
  2. Click Build -> Pipelines.
  3. You should see a new entry marked as Running.
  4. Click the status circle. You will see the pipeline graph.
  5. Click on the say-hello job to see the live console output from the Runner!

5. Troubleshooting the "Pending" State

If your pipeline stays in "Pending" for a long time:

  • Reason: You might not have any runners available.
  • Fix: Ensure you have verified your account with a credit card (GitLab requirement for shared runners) or install a specific runner on your computer.

Exercise: The Success Streak

  1. Modify your run-test job. Change exit 0 to exit 1.
  2. Push the change.
  3. Watch the pipeline. Did it turn Red (Failed)?
  4. Check the logs of the failed job. What does GitLab say?
  5. Fix it back to exit 0 and verify it turns Green again.
  6. Why is the "Live Log" the most important tool for a CI/CD engineer?

Summary

You have officially automated your first task. While this pipeline only prints "Hello," the same logic applies to compiling a complex Java app, building a Docker image, or deploying a global website.

Next Lesson: Protecting the secrets: Environments and Variables.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn