CJW
CJW

Reputation: 990

Use Gitlab CI/CD variables in YAML file

I have got a YAML configuration file in which I need to store an API key. As I do not want to commit my API Key to my Repo I figured a Gitlab CI/CD variable would be a good option. I have configured the variable in the Gitlab UI to be:

TOKEN = "123"

My .gitlab.ci.yml file contains:

image:
  name: xxx
variables:
  P_TOKEN: ${TOKEN}

And my YAML file has:

spec:
  command: test.sh
  env_vars:
  - TOKEN=${P_TOKEN}

But it just sets TOKEN in the YAML file to ${P_TOKEN} instead of the contents of ${P_TOKEN}. If I echo out my variables in my CI/CD pipeline it is set correctly.

Upvotes: 1

Views: 4812

Answers (1)

slauth
slauth

Reputation: 3178

So your YAML file is actually a template for a YAML file. You'd need to run some sort of template engine on top of it to have your ${P_TOKEN} placeholder replaced.

A very simple example using sed that might suffice for your use case:

sed -i "s/\${P_TOKEN}/$TOKEN/" your_file.yaml

Upvotes: 1

Related Questions