Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab CI/CD unset variables set in CI / CD Settings

Tags:

gitlab

I'm running a gitlab job and in the job I'm trying to unset certain variables set in CI / CD Settings.

For example, I have SOME_VARIABLE set to <some_value>

Then, in the job definition, I'm trying


variables:
   SOME_VARIABLE: ""
script:
    - echo SOME_VARIABLE - [%SOME_VARIABLE%]

But in the job itself I'm still getting

SOME_VARIABLE - [<some_value>]

instead of

SOME_VARIABLE - []

Has anyone came across this?

like image 777
Gyuri Avatar asked Mar 16 '19 08:03

Gyuri


1 Answers

I'll have to answer this since it might be rather obscure.

So turns out when you set a variable on Windows, you have to say

set v=some_value

To unset it, it needs to be

set v=

not

set v=''

When you set it to empty string it will be that, just quotes:

$ set v=""
$ echo %v%
""

If you unset it to empty correctly, you get:

$ set v=
$ echo %v%
%v%

However in gitlab, you can't leave values empty, such as

variables:
   v:

because the it's invalid syntax.

So what I had to do was unset the variable in the script area:

script:
  - set v=
  - run_my_script_that_needs_v_unset

Then the script worked as needed.

(I imagine it can be done similarly on the other platforms.)

like image 63
Gyuri Avatar answered Sep 28 '22 04:09

Gyuri