Hi Gitlab forum,
Hope you are fine!
I’m here with an issue into my CI/CD script.
Problem to solve
Overriding variables defined in GitLab’s UI in my gitlab-ci.yml script
I have variables defined in Gitlab’s UI and I’ve created a gitlab-ci.yml file that extends another one.
I would like to override in my extended job the value to a defined variable
Steps to reproduce
I’ve defined 2 variables into GitLab’s UI, into CI/CD settings
- SSH_SERVER_URL: the prod server SSH URL
- SSH_SERVER_URL_DEMO: the demo server SSH URL
Here is my .gitlab-ci.yml defined in my project with the 2 following jobs:
include:
- project: devops/skeleton
ref: main
file: ci-cd/deploy.yml
deploy_app_demo:
extends: .deploy_skeleton
variables:
SSH_SERVER_URL: $SSH_SERVER_URL_DEMO
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: '$CI_COMMIT_BRANCH == "demo"'
deploy_app:
extends: .deploy_skeleton
As you can see, the 2 jobs, depends on another one, which is defined into another file:
.deploy_skeleton:
stage: deploy
variables:
SSH_SERVER_URL: $SSH_SERVER_URL
PROJECT_NAME: $PROJECT_NAME
dependencies:
- build_app
....
My issue is the following one:
In my deploy_app_demo job, I want to override SSH_SERVER_URL with SSH_SERVER_URL_DEMO, defined in Gitlab’s UI setting.
Currently, it does not work. It seems that Gitlab’s UI defined variables take precedence on it (variable value is not overriden in my job logs).
Is there a way to tell to my job to override variables? I’ve tried using reference but not sure about the way to achieve it.
Thanks a lot for your help.
Best