Octopus Variables set export

Hello. I have a project in octopus with variables set.
During deploy process I use shell custom script (bash).
Right now I export variables from octopus to the deployment target this way:

export MY_VAR=#{VAR_FROM_OCTOPUS}

I do that for each variable. It works but in the future may be new variables will be added and I will have to change the script.
Is there way to export all variables at once?

Hi,

No, there’s currently no way to export all Octopus variables from a bash script.

Can I ask why you wish to export all? What is your scenario?

Hi Michael, thx for your answer!
I run build configuation from Team City, push source code to Octopus and it runs integration tests.
Integration tests use a variables from Octopus. If developer will add one more variable, he will have to add it in two places: in variable set and in the script. I want to avoid it and add var just in one place.

Maybe there is a way export all variables from a python script?

Ahh, I understand. It is painful to have to update multiple places.

A few possibilities:

Option 1: An approach I have seen used is to create another variable in Octopus, which value contains the script to set the required env vars. For example, you may name the variable IntegrationTestVariables with a value of:

export Apple="#{Apple}"
export Banana="#{Banana}"

You can then simply add this one variable to your bash script, ie. #{IntegrationTestVariables}, and the export statements will be substituted in.
The downside to this is that you have to remember to add a line to this variable whenever you add a new variable which you want to export. But, at least this is all done within Octopus variables, and it also lets you control exactly which variables are exported.

Option 2: Python is an option. When using Python scripts, Octopus creates a dictionary, octopusvariables, which you could iterate over. You can see this dictionary used in the python bootstrapper script which Octopus uses to execute your custom scripts.

Do either of these options appeal?