Environment Variables

Updated 1 day ago by David Venegas

Environment Variables can be created for all environments of a Deployment Flow or alternatively for a specific environment. 

Create Environment Variables in a Deployment Flow

  • Go to the deployment flow.
  • Click on Manage Environment Variables.
  • If it is a new variable, click on New, and provide the variable name.
  • 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 environments.
  •  You can add a new variable to the grid. This will result in creating the variable in all environments with an empty value.
  •  You can mass-edit the grid, once saved, all records will be updated. Renaming of the name of variables is fully supported.

To create a single Environment Variable, open the Environment record and click on the New Environment Variable button on the Environment Variables related list. 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 be unique on 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.

Environment variables are applied automatically in the following scenarios:

1. 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 another Environment Variables into the metadata during a deploy.

    2. Git Deployments

    When performing a deployment from Git, Copado will search the metadata files for any matching environment variable keys and replace them 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.

    3. Org to Org Deployments

    When performing an Org to Org Deployment, Copado will replace all maps from the source Environment Variables to the destination environments.

    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’

    4. 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. More information here.

    5. 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. More information here.

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

    6. Git Snapshots

    When clicking on the Create Snapshot Now button 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 another Environment’s Variables into the metadata during a deploy.

    7. 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 (the value in the destination environment). In the apex class files, any occurrences of {!Environment.AdminUser} would be replaced with 'admin.user.test@company.com'.

    Create Environment Variables in an Environment Record

    To create an Environment Variable, open the Environment record and click on the New Environment Variable button on the Environment Variables related list. 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.


    How did we do?