Environment variables are variables inside your deployment code that are set and managed through UbiOps. They can be useful for secure handling of credentials which you don't want to have hardcoded inside your deployment package, but also for parameters that you want to control or change without uploading a new deployment package file.
Environment variables can be defined on 3 different levels: project, deployment and deployment versions.
Project variables are shared between all deployment versions in a project.
Deployment variables are shared between all deployment versions of a deployment. If a variable with the same name of a project variable is defined as a deployment variable, the value will be overwritten by the deployment variable.
Deployment version variables are specific to the deployment version. If a variable with the same name of a project or deployment variable is defined as a deployment variable, the value will be overwritten by the deployment version variable.
Create an environment variable¶
To create a deployment level environment variable, go to a deployment in the UbiOps WebApp. Click on the Environment variables tab and then the Create variable icon. You can now create an environment variable by filling in its name and value.
You can create a deployment version level environment variable in the same way by going to Environment variables tab in a specific deployment version page.
You can set the environment variable to secret during creation. In this way, the value will not show up in API responses or logs. Provide the secret as True when you have sensitive information like passwords in your environment variable.
Copy environment variables¶
Alternatively, environment variables can also be created by copying over existing variables from a deployment or deployment version. Click on the Copy existing variables button next to the Create variable icon and select the source object which you would like to copy from. If the source object is a deployment, leave the 'Source version' field empty. All existing environment variables with the same name will be overwritten. Note that you need permissions to list the environment variables of the source object.
Using an environment variable¶
After creating the environment variable, you can use it in your deployment code. See the example below for accessing the variable named
import os variable = os.environ['MY_VARIABLE'] print(variable)
For more information, take a look at the Python documentation page.
variable <- Sys.getenv("MY_VARIABLE") print(variable)
For more information, take a look at the R documentation page.
Predefined environment variables¶
A couple of environment variable names are reserved for special functionality.
|SYS_DEPLOYMENT_FILE_NAME||Sets a custom name for the file that contains the deployment class and request method. Defaults to 'deployment.py'.|
|SYS_DEPLOYMENT_CLASS_NAME||Sets a custom name for the class in the deployment file that contains the request method. Defaults to 'Deployment'.|