Skip to main content

Exporting service variables as environment variables in a Shell Script step

You can use the Export Service Variables as Env Variables setting to export service variables as environment variables. This setting is available at account, organization, and project levels.

To enable this setting, go to Account Settings > Account Resources > Default Settings > Pipeline, and then expand Pipeline. Next, set the Export Service Variables as Env Variables setting to true.

Once you enable this setting, a service's variables are available as Bash variables in any Shell Script step in a stage that deploys that service. You can access the service variables like you access any Bash variables. For example, the service variable, var1 is available for use in a Shell Script step as $var1.

When you add a service variable, you can select variables of type String, Secret, or Number.

Let's consider an example where you have added the following service variables:

Variable nameTypeValue
svar1StringnormalValue
svar2Stringvalue-with-hyphen
svar3Stringvalue_with_underscores
secretServiceVarSecretyourSecret
nvar1Number1
svar4Stringabc%def%123
svar5$abcStringkey_With_Dollar
svar6Stringabc,ghj,klk

In your Shell Script step, you can use these service variables as environment variables if you had enabled the Export Service Variables as Env Variables setting.

Limitation

Shell scripts executing on remote hosts cannot export the correct value if you're using special characters such as -, _, $, %, and spaces in Bash.

When you run the pipeline, you can see the value of the service variables passed as environment variables.

See also