Variable levels
Project variables apply to all environments within the project. Environment variables apply to a specific environment or branch. An environment inherits variable definitions from the parent environment.
You can override an inherited value by defining the variable specifically for the environment. For example, to set variables for development, define the variable values in the .magento.env.yaml
file in the integration environment. All environments branching from the integration environment inherit those values. See Deployment configuration for details about configuring your environment using the .magento.env.yaml
file.
To set variables using the Cloud CLI:
-
Project-specific variables—To set the same value for all environments in your project. These variables are available at build and runtime in all environments.
code language-bash magento-cloud variable:create --level project --name <variable-name> --value <variable-value>
-
Environment-specific variables—To set a unique value for a specific environment. These variables are available at runtime and are inherited by child environments. Specify the environment in your command using the
-e
option.code language-bash magento-cloud variable:create --level environment --name <variable-name> --value <variable-value>
After setting project-specific variables, you must manually redeploy the remote environment for the change to take effect. Push the new commits to trigger a redeployment.
To set variables using the Cloud Console:
-
In the Cloud Console, click the configuration icon on the right side of the project navigation.
img-md w-36 -
To set a project-level variable, under Project Settings click Variables.
-
To set an environment-level variable, in the Environments list, select an environment and click the Variables tab.
-
Click Create variable.
-
Provide a name and value for the variable. Choose from the options:
- Available during runtime
- Available during buildtime
- JSON value
- Sensitive variable (value hidden in the console and CLI responses)
- Make inheritable (child environments can inherit environment-level variables)
-
Click Create variable.
note caution |
---|
CAUTION |
Setting environment-specific variables in the Cloud Console automatically redeploys the environment. |
Visibility
You can limit the visibility of a variable during build or runtime using the --visible-<build|runtime>
command. Also, there are options to set inheritance and sensitivity.
Use the following options to prevent a variable from being seen or inherited:
--inheritable false
—disables inheritance for child environments. This is useful for setting production-only values on themaster
branch and allowing all other environments to use a project-level variable of the same name.--sensitive true
—marks the variable as non-readable in the Cloud Console. You cannot view the variable in the user interface; however, you can view the variable from the application container, like any other variable.
The following demonstrates a specific case for preventing a variable from being seen or inherited. You can only specify these options in the CLI. This case does not pertain to all available environment variables.
magento-cloud variable:create --name <variable-name> --value <variable-value> --inheritable false --sensitive true
Verify variable levels and values
You can view a list of existing variables using the Cloud CLI.
magento-cloud variables
Variables on the project Project-Name (<project-id>), environment <environment-name>:
+----------------------------+-------------+-------------------------------------------+
| Name | Level | Value |
+----------------------------+-------------+-------------------------------------------+
| env:COMPOSER_AUTH | project | { |
| | | "http-basic": { |
| | | "repo.magento.com": { |
| | | "username": |
| | | "<public-key>", |
| | | "password": |
| | | "<private-key>" |
| | | } |
| | | } |
| | | } |
| ADMIN_EMAIL | project | admin@123.com |
| ADMIN_EMAIL | environment | admin@123.com |
| ADMIN_PASSWORD | environment | password |
| ADMIN_URL | environment | admin123 |
| ADMIN_USERNAME | environment | admin |
| php:newrelic.license | environment | xxxx71fb030366182117f955a22e4baf8exxxxxx |
+----------------------------+-------------+-------------------------------------------+