kbull
kbull

Reputation: 61

How to make Gitlab file type variable expansion within another file type variable work?

I would like to set up 2 file type variables and have the contents of the first imported/expanded/included in the second file type variable. The basic idea is a template of sorts (think .env file for name=value pairs) for the first file variable where the second file variable can just define and overwrite any settings defined in the first file variable.

For example, the first file variable named file1 might contain content such as:

DB_HOST=localhost

DB_USER=admin

Now in a second file variable named file2 I would like to do this:

$file1

DB_USER=newUserName

It would be great if file2 could override file1 such that the resulting file2 variable ends up becoming:

DB_HOST=localhost

DB_USER=newUserName

I tried variable expansion in the second file type variable using the variable name of the first file $file1 and ${file1} but neither one worked as long as the first file variable was specified as a type file. If I change the first one to just a variable then it kind of works. The contents of the variable is present in the second file but if a setting is defined in both variables it ends up being present twice in file2 like this:

DB_HOST=localhost

DB_USER=admin

DB_USER=newUserName

I would like to keep these name value pairs defined in gitlab variables and not in the .gitlab-ci.yml file for a couple of reasons, ease of changing a value and making a change does not require commits to the repo.

Is there a better way to accomplish this or is this the only option I have?

Upvotes: 0

Views: 25

Answers (0)

Related Questions