Get environment variables, and assign an optional default value to context if the sought environment variables do not exist.
The difference between
pypyr.steps.envget and pypyr.steps.env
, is that
pypyr.steps.envget won’t raise an error if the $ENV doesn’t exist.
envget context key must exist.
All inputs support substitutions.
- name: pypyr.steps.envget description: if env MACAVITY is not there, set context theHiddenPaw to default. in: envGet: env: MACAVITY key: theHiddenPaw default: but macavity wasn't there!
env: Mandatory. This is the environment variable name. This is the bare environment variable name, do not put the $ in front of it.
key: Mandatory. The pypyr context key destination to which to copy the $ENV value.
defaultOptional. Assign this value to
keyif the $ENV specified by
- If you want to create a key in the pypyr context with an empty
- If you do NOT want to create a key in the pypyr context, do not have a default input.
- If you want to create a key in the pypyr context with an empty value, specify
# save ENV_NAME to key. If ENV_NAME doesn't exist, do NOT set saveMeHere. envGet: - env: ENV_NAME key: saveMeHere # saveMeHere won't be in context if ENV_NAME not there. # this is because the default keyword is not specified.
If you need to get more than one $ENV, you can pass a list to
envGet: # get >1 $ENVs by passing them in as list items - env: ENV_NAME1 # mandatory key: saveMeHere1 # mandatory default: null # optional - env: ENV_NAME2 key: saveMeHere2 default: 'use-me-if-env-not-there' # optional