In this article I will show how to use custom variables in your GitLab CICD pipeline.
GitLab has 2 types of variable
- Predefined Variables - CI Variables
- 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
ex - $MICRO_SERVICE_NAME
stages:
- test
run_unit_test:
stage: test
before_script:
- echo "Prepearing test data..."
script:
- echo "Running unit tests for microservice $MICRO_SERVICE_NAME ..."
after_script:
- echo "Cleaning up temporary files.."
- rm -r test-data
- ls
Thank you :)
Top comments (0)