0

Is it possible in a gitlab CICD pipline to build a variable dynamically with a variable? Sample: i have a variable in gitlab "TEST_MASTER".

script:
- echo "$TEST_"$CI_COMMIT_BRANCH""

I need the result from the variable TEST_MASTER, but the part of MASTER must come from the branch variable.

Husker
  • 49
  • 2
  • 11

1 Answers1

0

That looks like a bash script to me so assuming TEST_MASTER already has a value, you should be able echo it like this:

script:
- myvar=TEST_"$CI_COMMIT_BRANCH"
  echo "${!myvar}"

For more information, check this question and it's answers

Xander
  • 1
  • well, it not only partly bash! it comes from the gitlab-ci.yml. Yes, you can run bash here but the variables are not available at bash level, the values from the variables are sort of inserted on execution. – Husker Jul 15 '21 at 10:52
  • 1
    master `$ myvar=TEST_"$CI_COMMIT_BRANCH"` `$ echo "${!myvar}"` `/bin/sh: eval: line 136: syntax error: bad substitution` `Cleaning up file based variables` Unfortunately does not work! – Husker Jul 15 '21 at 11:03