Setting Environment Variables
Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule reached its End of Life on November 2, 2022, when Extended Support ended. Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted. MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements. |
If you’re deploying multiple applications as a shared resource, do not set any properties in the project properties files. This might cause conflicts among the various applications that share a domain. Instead, set environment variables over the scope of the deployed application, its domain, and other applications under that domain.
Environment variables set in Studio are only used when you deploy using the Mule runtime engine within Studio.
When you deploy applications on-premises, define system properties from the command line when you start the Mule instance or through the wrapper.conf
file to use them as environment variables. See Set System Properties for On-premises Deployments for instructions.
Set Environment Variables in Anypoint Studio
Follow these steps:
-
Open the dropdown menu next to the Play button and select Run Configurations….
-
Select the corresponding Run configuration. If a Run configuration does not exist for your project, you can create one by using the New launch configuration button:
-
Select the Environment tab, and add the variables you need.
The environment variables you create are defined at the domain level. These will affect all of the applications associated with that domain when you deploy locally using Studio.
Environment variables defined in Studio only work when you run the application in the Mule runtime engine within Studio. This configuration does not affect design time operations such as DataSense, automatic completion, or validation.
Accessing Environment Variables
To reference an environment variable, regardless of how it was defined, use the following syntax:
${variableName}
For example, if you want to reference the myVar
variable that was set in Studio in the previous example, use the following syntax:
<logger message="${myVar}" doc:name="Environment Variable Set in Studio" />
Or, if you want to reference a variable that is defined in the OS, you can simply use the following syntax:
<logger message="${USER}" doc:name="Environment Variable Set in OS" />