how to copy ENV variables to another device ?

Hi,
we use balenaOS to distribute our SW to devices remotely.

And we use ENV variables that define the necessary switches per device or installation.

We use production (not developement) images.

Now my question: How can I easily copy/paste ENV variables from one device to another ?

I thought of using balena push <fleet_name> --env my_env=my_env_value. But this does not seem to work. Any other ideas ?

I also saw that there is a balena push <flee_id>.local --env my_env=my_env_value - however that only works for a development image (not production like we work with).

Thank you for any support on this.

Hi,
Do you need the ENV variables at build-time or at run-time? If it is the latter, you can use a balenaCloud runtime variables, as reference here in our documentation. Let me know if this answers your question!

We use ENV variables at run-time. And I do already use balenaCloud runtime-variables as you reference.

And exactly those I would like too copy paste to another device ! (or fleet if its fleet-variables).

I can only copy them by entering one by one manually into the next device. But what I would like much rather is to export an ENV-set and to import the entire set to the next device (or fleet if its fleet-variables). Can you do that ?

Hi,

do you think using balena-cli, see env vars here: balena CLI Documentation - Balena Documentation
would be helpful?
You can easily create a reusable script to read the ENV vars from a device and to add them to another.

Thank you @mcraa, this helped.

To read ENV variables, I can use:

balena envs --device <my_device_id>

or for a fleet:

balena envs --fleet <my_fleet_name>

After receiving from one device (or fleet), I was able to write to another device or fleet.

I made two scripts using the Balena CLI:

Script for adding ENV variables to a fleet:

#!/bin/bash
# 
balena env add MY_ENV_KEY1  my_env_value1  --fleet $1
balena env add MY_ENV_KEY2  my_env_value2  --fleet $1
balena env add MY_ENV_KEY3  my_env_value3  --fleet $1
balena env add MY_ENV_KEY4  my_env_value4  --fleet $1

To execute, in a Terminal, type:
bash add_fleet_ENVs.sh <my_fleet_name>

Script for adding ENV variables to a device:

#!/bin/bash
# 
balena env add MY_ENV_KEY1  my_env_value1   --device $1
balena env add MY_ENV_KEY2  my_env_value2   --device $1
balena env add MY_ENV_KEY3  my_env_value3   --device $1
balena env add MY_ENV_KEY4  my_env_value4   --device $1

To execute, in a Terminal, type:
bash add_device_envs.sh <my_device_id>

1 Like