Home > Software engineering >  How to access GitLab CI/CD Variable in Ruby Recipes?
How to access GitLab CI/CD Variable in Ruby Recipes?

Time:09-14

I have declared some variables in Gitlab -> Settings -> CI/CD -> Variables.

I want to access these variables in ruby (.rb) files for chef cookbook recipes.

I have declared a variable named "TEST_VARIABLE" in settings as: Gitlab -> Settings -> CI/CD -> Variables :- Key = TEST_VARIABLE, Value = TEST_VALUE

I have tried accessing them in the below format in the ruby(.rb) recipes. $TEST_VARIABLE, ${TEST_VARIABLE},TEST_VARIABLE, #{TEST_VARIABLE} and ENV['TEST_VARIABLE'] But nothing works, all returns blank or nil value.

Please let me know how to access these variables in the .rb file.

CodePudding user response:

I dont think that you can use pipeline variables in normal source code. Maybe you can set in your script section a shell environment variable and access it in your ruby code.

script:
 - export TEST_VARIABLE=$TEST_VARIABLE

CodePudding user response:

You can pass the variables to the ruby script when you call it.

script:
 - ./rubyscript $TEST_VARIABLE
  • Related