Multi-line Environment Variables

envars

#1

Hi, so I’m having trouble making use of environment variables.

The context of my situation is: I have a NodeJS script that hits some endpoints on the Google Drive API and uses JSON Web Token to authorize, so I need to make use of the private key (which is multi-line) from a json file provided by Google Drive’s dev console.

I’m able to get it working after SSHing into the circle ci build environment since I’m able to store (via copy and paste) a multi-line string into an environment variable. However, working with the CircleCI settings does not allow me to do this. Does anybody know of a workaround? (or if I’m just approaching this wrong entirely? to my understanding BUILD SETTINGS > ENV VARIABLES is one of the places where sensitive info is intended to be kept)

So far the things I’ve tried include:

  • copy and pasting my api key with the link breaks (no \n, just ‘return’, which when pasting into the environment variables, appears as a whitespace character, presumably causing the auth fail)
  • leaving the line break characters (’\n’) in the string
  • some variations of the former 2 (such as removing spaces, adding a space behind line break, etc.), none of which are successful.

Any help would be appreciated. Can clarify if necessary.


#2

Resolved. For those who are running into a related issue, the following worked for me:

Base64 encode your env vars before putting them into Build Settings > Env Variables, b64decode at runtime.


#3