Can't access environment variables in shell scripts

envars

#1

Hi all!

I’m new to CircleCi so hopefully I’m just missing something obvious but I can’t seem to access any of the environment variables I created in the settings GUI.

Say I have the config of:

deployment:
branch: development
commands:

  • ./myscript.sh

The script runs and but anytime I try and access an environment variable with $MY_ENV_VAR it is empty.

(also, fwiw printenv works and doesn’t show my custom env variables either.)

Is this even possible?

Thanks for the help!


#2

Did you find a resolution or workaround for this?


#3

Seeing this I think of the following questions:

  1. How are you setting these variables?
  2. Are the variable names using anything other than alphanumeric characters?
  3. Is this a fork/PR build?
  4. Was a new build (from a new commit) done in order to test for the environment variable?

#4
  1. Setting in GUI on Circleci.com for Jest repo.
  2. No, just alpha numeric keys.
  3. This is a PR build and I’m SSHing into the session. In my case I am unable to echo $ENVVAR.
  4. These keys have been here prior.

#5

@ericnakagawa and @ktstowell can you take a look at this post and let me know if its the same issue that I answered there: Gemnasium and CircleCI - GEMNASIUM_TOKEN seems to not get picked up

If this is not a forked PR build, please give me a build URL so I can take a look.


#6

Ah, yes. In my case it is a forked PR! The justification makes sense. Any way for this to be added to docs?


#7

Where would you expect to see this information being added in Docs? To the page about environment variables? A page explaining all about forks and PRs and how settings might change? Something else?


#8

This is actually in the docs, but might be buried away somewhere. https://circleci.com/docs/1.0/fork-pr-builds/#security-implications

cc @FelicianoTech maybe we can find a better place to put this?


#9