How to use File environment variable in Gitlab CI

Viewed 113

I have a private key for deployment which I have set as a File Environment variable in the gitlab ci settings. However when I try and do

echo $VAR

the output is the entire contents of the key something like

----BEGIN PRIVATE KEY---
dfbvjladfbgvjksadbavkjabdfjnvkdjbnv;sdf98qw374yriuebglvkjsdfgydjkfvnldafkjbvgjkaldb
----END PRIVATE KEY---

I would like to have this key stored in a file and would like the path to the file as the environment variable $VAR. I am unsure of how to do this. Any help will be appreciated.

1 Answers

There was a couple of mistakes with respect to using the Environment variables.

The environment variables when declared in settings need not be imported in the yaml files as variables.

Mistake

variables:
    VAR : $VAR

This leads to the contents of the file being exposed in the log which we dont want in this case.

Correct Way:

We can just use the key as is in the yaml with $VAR this should give a temporary path to the file where the key is stored.

Related