How to pass Gitlab env var with sensitive characters to bash script?
Surprisingly indeed GitLab works weirdly with the env vars.
It evaluates them internally, though it shouldn't in my view.

Value set as (in project Settings > CI/CD > Variables): 'aaa$bbb*%'
becomes 'aaa*%'
(with single quotes left!)

Couple of of proof links:


https://gitlab.com/gitlab-org/gitlab-ce/issues/45173#note_101659865
https://gitlab.com/gitlab-org/gitlab-ce/issues/27436


Workarounds:

1)
You can duplicate dollar ($) sign, i.e.: aaa$$bbb*%
(as mentioned on the first link above).

2)
Use base64 to encode and decode the value.

Do this first:

$ echo 'aaa$bbb*%' | base64
YWFhJGJiYiolCg==


Then store this value in project Variables.

And then in your script decode it:

PASS=$(echo ${sensitive_var} | base64 -D)