Setting Up CI/CD Pipelines for Your Projects Using GitLab Runner

Leave a comment on Setting Up CI/CD Pipelines for Your Projects Using GitLab Runner

Continuous Integration and Continuous Deployment (CI/CD) are essential practices in modern software development. Automating your workflows ensures consistent code quality, faster deployments, and reduced human error. GitLab Runner, a lightweight agent that executes CI/CD jobs, helps streamline this process. In this guide, we will walk you through setting up a CI/CD pipeline using GitLab Runner.

Before you begin, ensure you have the following:

  • A GitLab account with a repository.
  • A server or local machine to install GitLab Runner.
  • Docker (recommended) or another supported executor.
  • Basic knowledge of YAML and Git.

Lets start the process now. (Here we use an Ubuntu 22.04 server)

Step 1 – Install GitLab Runner

curl -L –output /usr/local/bin/gitlab-runner

https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

chmod +x /usr/local/bin/gitlab-runner

useradd –comment ‘GitLab Runner’ –create-home gitlab-runner –shell /bin/bash usermod -aG docker gitlab-runner

Step 2 – Register GitLab Runner

Once installed, register the runner to connect it with your GitLab project.

gitlab-runner register

You’ll be prompted for:

  • GitLab instance URL (e.g., https://gitlab.com/)
  • Registration token (found in Settings > CI/CD > Runners in GitLab)
  • Description and tags (optional)
  • Executor type(e.g., docker, shell, virtualbox) Example for Docker executor:

gitlab-runner register –non-interactive –url “https://gitlab.com/” –registration-token “YOUR_TOKEN” –executor “docker” –docker-image “alpine:latest”

Make sure you replace both ‘https://gitlab.com/’ and ‘YOUR_TOKEN’ with the actual onces.

Step 3 – Configure .gitlab-ci.yml

You should create a.gitlab-ci.yml file in the repository root. This file defines the pipeline stages and jobs.

Example configuration:

stages:

  • build
  • test
  • deploy

build-job:

stage: build script:

  • echo “Compiling project…”
  • make build

test-job:

stage: test script:

  • echo “Running tests…”
  • make test

deploy-job:

stage: deploy script:

  • echo “Deploying application…”
  • make deploy only:
  • main

This configuration runs a build, test, and deploy sequence whenever changes are pushed.

Step 4 – Start and Verify GitLab Runner

Start the GitLab Runner service:

sudo gitlab-runner start

Check if the runner is active in GitLab under Settings > CI/CD > Runners. To trigger the pipeline, push a commit to your repository:

git commit -m “Add CI/CD pipeline”

git push origin main

You can monitor the pipeline progress under CI/CD > Pipelines in GitLab.

Conclusion

Setting up GitLab Runner for CI/CD ensures automated, efficient, and reliable software deployment. By defining jobs in .gitlab-ci.yml, you can build, test, and deploy applications seamlessly. Start integrating CI/CD into your workflow today to accelerate development and improve project stability!

Server Hosting Solutions by RackNerd:

Shared Hosting
cPanel Web Hosting in US, Europe, and Asia datacenters
Logo
Reseller Hosting
Create your new income stream today with a reseller account
Logo
VPS (Virtual Private Server)
Fast and Affordable VPS services - Instantly Deployed
Logo
Dedicated Servers
Bare-metal servers, ideal for the performance-demanding use case.
Logo

Leave a comment

Your email address will not be published. Required fields are marked *