How to Access Environment Variables with Code
Overviewβ
When a user provides input via Blueprint Variables, or you pass values to your script using environment variables, you'll want to make sure that you can access these values in your code. This how to guide will walk you through the steps to access environment variables.
note
When accessing the contents of an environment variable in your code, we recommend storing it as a variable so it can be continuously used.
Stepsβ
For this example, our environment variable will be named OPERATOR_A
.
- Navigate to the location of your code (local, GitHub, etc.)
- Select the language your code is written in from the tabs below.
- Python
- Bash
- Node
import os
os.environ.get('OPERATOR_A','default value')
${OPERATOR_A}
process.env.OPERATOR_A;
- Add the above snippet to your code.
success
You've now successfully written code to access an environment variable.