Escape char in Gitlab Secret Variables
Asked Answered
M

3

15

I have a secret var :

enter image description here

But when I do - echo %MySecretVar%, runner displays foo only

How can i escape special chars like ! in Gitlab Secret Vars ?

Marjoram answered 19/2, 2018 at 16:51 Comment(1)
Have you tried ^^! or ^! ? I never used Gitlab myself but I remember reading somewhere that this should work ...Affray
W
23

I had the same problems with Gitlab, job running on windows, but I assume it will reproduce on Linux as well, because it seems Gitlab parsing issue or relay weird escaping.

So I have set environment variable

APPPOOL_PWD: 'blabla!foo$bar'

and output of echo %APPPOOL_PWD% or echo $APPPOOL_PWD was 'blabla'

The Gitlab seems to be was eating out the exclamation mark sign ! and dollar sign $. To avoid it as proposed in comment for exclamation mark I have used ^^ and for dollar sign I have used $$ as proposed in the Gitlab variables documentation.

So following variable works well:

APPPOOL_PWD: 'blabla^^!foo$$bar'

and output of the echo command in this case would be 'blabla!foo$bar'.

Warila answered 8/6, 2018 at 10:38 Comment(0)
I
1

I was able to use a value with special characters this way:

  1. Define Gitlab CI variable FOO with special characters in the value, e.g. ?!asdf&%fghjkl
  2. In .gitlab-ci.yml define:
variables:
  bar: '"%FOO%"'
script:
  - echo %bar%

This way the variable will stay exactly the way it is typed in your CI variable field.

I'm using Windows batch shell. If you use another shell for script running, the syntax is a little different from %bar%. Check out the syntax here: Gitlab CI reference

Imaginative answered 29/5, 2019 at 11:50 Comment(0)
D
0

I am using GitLab 15.3.3-ee and I don't see any issue with the ! it get's passed through. However for $ you will have to use extra $ as escape character, just like mentioned in the first comment.

Dismay answered 20/9, 2022 at 9:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.