Creating Environment Variables

Updated 1 month ago by Copado Solutions

Environment variables can be created in all the environments of a pipeline directly from the Pipeline record or, alternatively, in a specific environment from the Environment Variables related list in the Environment record. 

Let’s see how you can create an environment variable using these two options.

Creating an Environment Variable from a Pipeline Record

  1. Navigate to a Pipeline record.
  2. Click on the drop-down menu in the upper right corner and select Manage Environment Variables.
  3. Click on New and give your variable a name. For example, if you want to create a variable to store username values, you can name it Username:
Please note that if you want to define a scope for your variable, you need to create it from the related list in the Environment record.
Please make sure that the variable name and its value are not the same, as it could lead to errors.
  1. Once created, provide the specific values for each of the environments in the pipeline:
If you leave any of the environments empty, you won’t be able to save the variable, and an error message will be displayed.

To remove a variable from the grid, you can click on the Del link. This will result in deleting the variable in all the environments. If you add a new variable to the grid, the variable will be created in all the environments with an empty value.

You can also mass edit the grid. Once saved, all the records will be updated. The renaming of variables is fully supported.

Creating an Environment Variable in an Environment Record

  1. Navigate to the Environment Variables related list in an existing Environment record.
  2. Click on New to create a new variable:
  3. Give your variable a name, e.g., URL,  and set a value, e.g., https://copado-uat-dev-ed.lightning.force.com/.
    Please note that environment variable values do not support RegEx or the * character.
  4. The Scope field allows you to specify where a particular variable is applied. If you want the variable to be applied to all occurrences of the value across all files, you can leave this field empty. Otherwise, if you want the variable to be applied to a specific metadata type, for instance, you can use this field to define the scope of the variable.

Scope supports a serialized list of values separated by the semicolon (;) delimiter. 

The scope options are the following:

Use Case

Expression

Example

Use this expression if you want the variable to be applied to a specific metadata type

<DirectoryName>/*

objects/*

If you use this expression, the variable will be applied to a specific item within a particular metadata type

<DirectoryName/FileName.FileExtension>

object/Account.object

Custom settings: You can choose to get variables applied to all custom settings

<CustomSettingValues/*>

CustomSettingValues/*

Custom settings: You can choose to get variables applied to a specific custom setting

<CustomSettingValues/FileName.FileExtension>

CustomSettingValues/SAP_URL__c.object

Custom Labels: The variable will be applied to all components. 

Note: You cannot specify the component since custom labels are stored in a singular file.

labels/CustomLabels.labels

The variable will be applied to Apex steps

AnonymousApex/*

AnonymousApex/*

Use this expression if you want the variable to be applied to Data deployment steps

DataDeploymentStep/*

DataDeploymentStep/*

All objects and a specific apex class

object/*;classes/accountwrapper.cls

Copado enforces a constraint on environment variables with unique scope-values and its behavior is based on the following hierarchy structure:

  • If the same value is used in two different environment variables with overlapping scope, the more specific scope will win.
  • If the scope is empty for the same value in two or more environment variables, no replacement will be done. The value should be unique if no scope is defined.
  • Scope and value combination should be unique across all environment variables.

For more information about environment variables, please refer to the Environment Variables article.


How did we do?