Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable inside variable gitlab ci

Is there a way to use predefined variable inside custom variable in gitlab ci like this:

before_script:
  - cat "${$CI_COMMIT_REF_NAME}" >> .env

to extract the name of branch from $CI_COMMIT_REF_NAME and use it as a name of custom variable

Update:

enter image description here

like image 588
wspven Avatar asked Mar 27 '26 04:03

wspven


1 Answers

Check if this matches gitlab-org/gitlab-runner issue 1809:

Description

  • In the .gitlab-ci.yml file, a user can define a variable and use it in another variable definition within the same .gitlab-ci.yml file.
  • A user can also use a GitLab pre-defined variable in a variable declaration.

Example

variables:
  variable_1: "foo"           # here, variable_1 is assigned the value foo
  variable_2: "${variable_1}" # variable_2 is assigned the value variable_1. 
  #  The expectation is that the value in variable_2 = value set for variable_1

If it is, it should be completed/implemented for GitLab 14.1 (July 2021)

like image 194
VonC Avatar answered Mar 31 '26 09:03

VonC