Getting Started with Gitlab CI/CD Pipeline

GitLab CI/CD pipelines automate software delivery from development to deployment. This guide shows how to create a pipeline: ensure runners are available, create a .gitlab-ci.yml file with build, test, and deploy stages, then monitor execution through GitLab's interface.

Table of contents

In the modern world of software development, Continuous Integration and Continuous Deployment have become essential practices. 

CI/CD is a continuous software development method involving ongoing building, testing, deploying, and monitoring of iterative code changes. Learning GitLab CI/CD is invaluable for catching bugs early in development and ensuring adherence to established code standards in production deployments.

In this blog, we'll guide you through a hands-on and step by step demo on “How to create a CI/CD pipeline in the Gitlab”.

Why Gitlab CI/CD Pipeline?

Now you might be wondering, or a question comes into your mind that there are so many tools like CircleCI, Github Actions, Jenkins, etc available in the market, then what makes Gitlab CI special?

  • Gitlab CI provides great issue tracking and issue shuffling features, and it also allows you to parallel test pull requests and branches. 
  • GitLab simplifies monitoring by displaying test results directly within its user-friendly interface. 
  • Compared to Jenkins, GitLab offers a more intuitive experience, making it easier to navigate and work with during testing workflows.

Prerequisites 

Before creating the CI/CD Pipeline in Gitlab, make sure that you have followed :

  1. A GitLab account
  2. Create a Blank Project
  • On the left sidebar, at the top, select Create new (+) and New project/repository.
  • Select Create Blank Project.
  • Enter the project details as per your requirements.
  • Select Create project.

So, now you’ve set up your Gitlab account and created a project in Gitlab. Let’s keep the momentum going and follow the next steps.

Step-by-Step guide to build a Gitlab CI/CD pipeline 

Step 1: Ensure you have all runners available:

  • In GitLab CI/CD pipelines, runners are the agents responsible for running your CI/CD jobs in a pipeline. 
  • But if you are using gitlab.com(the web-hosted version of GitLab), then you don’t need to install runners manually, as GitLab provides them by default.
  • To check and ensure that you have all runners available and running.
  1.  Go to your project in Gitlab.
  2. Navigate to Settings > CI/CD > Runners.

Step 2: Navigate to the root directory:

In your local git repository, make sure you are in the root directory.

Step 3: Create a Gitlab YAML file:

  • Create a Gitlab YAML file named .gitlab-ci.yml file. 
  • .gitlab-ci.yml is a YAML file in which you define the instructions for the CI/CD pipeline or what jobs you want to perform by defining all the stages like building, testing and deploying.
  • For creating a .gitlab-ci.yml file in your project 
  1. Navigate to the project’s main page in GitLab.
  2. Navigate to the project and click on the (+) icon on the right-hand side of the project name.
  3. From the drop-down menu, select the “New File”.
  1. In the filename, enter.giltlab-ci.yml.
  2. Define the pipeline stages and jobs within this file.
stages:
  - build
  - test
  - deploy

build-job:
  stage: build
  script:
    - echo "Building the project..."

test-job:
  stage: test
  script:
    - echo "Running tests..."

deploy-job:
  stage: deploy
  script:
    - echo "Deploying the application..."

  1. Now commit to the main branch to automatically trigger and start executing the defined stages.

Step 4: Monitor the status and result of the CI/CD Pipeline

Once the .gitlab-ci.yml  The file is committed, and Gitlab automatically triggers the pipeline as defined in the configuration file.

To view the status of the Gitlab CI/CD pipeline:

  1. Navigate to the project main page and go to Build > Pipelines.
  1. Click on the pipeline to inspect. This will open a visual representation of your pipeline, showing all the stages like build, test, deploy In what order do you define the .gitlab-ci.yml file.
  1. Navigate to the jobs section to view the particular jobs in the pipeline.
  1. Click on the job for a detailed view of how the execution of that particular job is done.

Limitations of GitLab CI/CD Pipeline

While Gitlab provides the CI/CD pipeline, when it comes to Kubernetes or managing infrastructure state, Gitlab currently lacks GitOps integration, and this leads to the installation of more tools like Argo CD and Flux CD, which increase the operational overhead.

Automate CI/CD using Devtron

Devtron simplifies the CI/CD pipeline by providing native integration with GitOps and tools like Argo CD. Devtron automates the entire workflow, making it seamless and easy to deploy on Kubernetes and ensuring consistent, reliable deployment while reducing operational overhead.

Devtron not only automates your CI/CD pipeline, but it also brings features that go beyond pipeline automation.

Explore more Devtron Features and explore how you can build a Kubernetes CI/CD pipeline with Jenkins (CI) and ArgoCD (GitOps CD), then do check out this blog: Kubernetes CI/CD Pipelines with Jenkins and ArgoCD.

Conclusion

GitLab CI/CD pipelines provide automation and streamline the entire software delivery process from development to deployment. Whether building a new pipeline or improving an existing pipeline, Gitlab becomes a reliable partner that helps you move faster, catch issues early, and build.

FAQ

What is GitLab CI/CD used for?

GitLab CI/CD can identify the bugs early in the software development lifecycle through automates testing and continuous integration.

What is the difference between Jenkins and GitLab CI/CD?

GitLab is an integrated DevOps platform that offers version control, CI/CD, issue tracking, and code review. Jenkins is an automation server primarily focused on CI/CD, automating tasks like building, testing, and deploying code changes.

What are GitLab CI file?

GitLab CI file named as .gitlab-ci.yml is the file in which you define the instructions for the CI/CD pipeline, or what jobs you want to perform by defining all the stages, like building, testing, and deploying

What are the GitLab runners?

GitLab runners are the agents responsible for running the jobs in a GitLab CI/CD pipeline and are also used for building, test, deploy the project.