pypyr.steps.envget permalink

get environment variables into context permalink

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.

The envget context key must exist.

All inputs support substitutions.

See a worked example for getting environment variables with defaults here.

get an environment variable with a default fallback permalink

- 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.
  • default Optional. Assign this value to key if the $ENV specified by env doesn’t exist.
    • If you want to create a key in the pypyr context with an empty value, specify null.
    • If you do NOT want to create a key in the pypyr context, do not have a default input.

get environment variable with no default permalink

# 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.

get multiple environment variables in one step permalink

If you need to get more than one $ENV, you can pass a list to envget.

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

see also

last updated on .