The Ops Community ⚙️

Cover image for How to use custom variables in GitLab CICD pipeline
Bawantha Thilan
Bawantha Thilan

Posted on

How to use custom variables in GitLab CICD pipeline

In this article I will show how to use custom variables in your GitLab CICD pipeline.

GitLab has 2 types of variable

  1. Predefined Variables - CI Variables
  2. Define own variable - we can create our own variables

This is a simple use case where we can use variables in our pipeline

let say you want to run pipeline for multiple microservices that your team is developing and we want to pass microservice name to our pipeline

first define your variables in GitLab project settings

  • key - variable name
  • value - variable value

And now we can use our variables in cicd pipeline

you can use this in your pipeline by putting a $ sign in front of your variable name


  - test

  stage: test
    - echo "Prepearing test data..."
    - echo "Running unit tests for microservice $MICRO_SERVICE_NAME ..."
    - echo "Cleaning up temporary files.."
    - rm -r test-data
    - ls

Enter fullscreen mode Exit fullscreen mode

Thank you :)

Top comments (0)