CircleCI Ideas

Fail if environment variable doesn't exist

When you use an enviroment variable & forget to set this (e.g. in a context), shell's default is to silently use an empty value instead of returning with an error.

The option -o nounset would always throw a helpful error message when the environment variable doesn't exist/is unset. That option also works for in the shell used in Alpine Linux (which is used for many official Docker images):

$ docker run alpine sh -c 'set -o nounset; echo $TEST_ENV'

sh: TEST_ENV: parameter not set

Related Discuss post

  • Avatar32.5fb70cce7410889e661286fd7f1897de Guest
  • Mar 9 2020
  • Taking votes
  • Attach files