Environment Variables

Updated 1 week ago by Copado Solutions

Environment variables can be created in all the environments of a deployment flow or, alternatively, in a specific environment. 

Creating Environment Variables in a Deployment Flow

  1. Navigate to the deployment flow.
  2. Click on the drop-down menu in the upper right corner and select Manage Environment Variables.
  3. If it is a new variable, click on New and provide the variable name.

  4. Once created, provide your values specific to each environment in the deployment flow.

  • You can remove a variable from the grid. This will result in deleting the variable in all the environments.
  •  You can add a new variable to the grid. This will result in creating the variable in all the environments with an empty value.
  •  You can mass edit the grid. Once saved, all the records will be updated. Renaming variables is fully supported.

Creating Environment Variables in an Environment Record

  1. Open the Environment record and click on New Environment Variable in the Environment Variables related list.
  2. Choose a name, for example: ‘URL’ and set a value, such as ‘http://test.mysite.com'.

Environment variables are designed to contain strings which are unique to a specific environment, such as Salesforce ids, integration endpoints or usernames.

Environment variables should have unique names and values, i.e. there cannot be variables in the same environment with the same value. This is to guarantee a proper replacement process in all scenarios, whether replacements are Value to Key or Key to Value.
Environment variables do not support RegEx or the * character.

Where Are Environment Variables Applied?

Environment variables are applied automatically in the following scenarios:

  • Commits
    When performing a Git commit, Copado will search the metadata files for any matching environment variable values and replace them with the corresponding key.
    E.g. Environment variable: AdminUser = admin.user.test@company.com. In the metadata files, any occurrences of ‘admin.user.test@company.com’ would be replaced with {!Environment.AdminUser} This then allows Copado to replace other environment variables in the metadata during a deploy.
  • Git Deployments
    When performing a deployment from Git, Copado will search the metadata files for any matching environment variable keys and replace then with the corresponding value.
    E.g. Environment variable: AdminUser = admin.user.uat@company.com. In the metadata files, any occurrences of {!Environment.AdminUser} would be replaced with admin.user.uat@company.com.
  • Org to Org Deployments
    When performing an org to org deployment, Copado will replace all maps from the source environment variables with the destination environment.
    E.g. Source environment variable: AdminUser = admin.user.test@company.com Destination environment variable: AdminUser = admin.user.uat@company.com. In the metadata files, Copado will replace any occurrences of ‘admin.user.test@company.com’ with ‘admin.user.uat@company.com’
  • Custom Setting Deployment
    When performing a custom setting deployment step, Copado will search in the custom setting fields for any matching environment variable values and replace them with the corresponding value of the destination environment. Click here for more information.
  • Branch Management - Validation / Deployment
    When running branch validation, Copado will validate that a branch is mergeable and deployable. As part of this, Copado will replace environment variables in the metadata files just like during a Git deployment. Click here for more information.

Environment variables can also be referenced, if required, in the following scenarios:

  • Git Snapshots
    When clicking on Create Snapshot Now in a Git snapshot, a popup appears with a checkbox called Apply Environment Variables. If checked, Copado will search the metadata files during the snapshot process for any matching environment variable values and replace them with the corresponding key.
    E.g. Environment variable: AdminUser = admin.user.test@company.com In the metadata files, any occurrences of ‘admin.user.test@company.com’ would be replaced with {!Environment.AdminUser} This then allows Copado to replace other environment variables in the metadata during a deploy.
  • Apex Anonymous Deployment Step
    When performing an Apex Class step within a deployment, Copado will search in the script for any matching environment variable keys (e.g. {!Environment.AdminUser} ) and replace them with the corresponding value (e.g. admin.user.test@company.com). 
    E.g. Environment variable: AdminUser = admin.user.test@company.com (value in the destination environment). In the Apex Class files, any occurrences of {!Environment.AdminUser} would be replaced with 'admin.user.test@company.com'.


How did we do?