Feature/sc 136671/env vars
Description
This PR introduces a new env-vars feature that enables managing environment variables directly from the Particle Cloud and integrating them into the project build workflow.
Key Capabilities
1. Cloud Environment Variable Management
-
List environment variables for a specific context:
-
device -
product -
organization
-
-
Patch environment variables:
- set new variables
- unset existing variables
2. Build & Bundle Enhancements
- The CLI can now bundle environment variable files into a project build when:
- The project includes a
project.propertiesfield namedfirmwareEnvreferencing one or more env-var files. -
OR the user provides an explicit
--env <path>flag during bundling.
- The project includes a
- Env var files are packaged into the final bundle in JSON format.
This feature streamlines workflows where firmware requires cloud-managed configuration and ensures consistent, reproducible builds by incorporating environment variables directly into the firmware asset bundle.
How to Test
1. Listing Environment Variables
Run each command and verify the returned JSON reflects the env vars configured in the cloud:
particle env-vars list --device <deviceId>
particle env-vars list --product <productId>
particle env-vars list --org <orgSlug>
outcome Expected: CLI returns all env vars for the selected scope.
2. Setting and Unsetting Environment Variables
Set variable:
particle env-vars set <<KEY>> <<value>> --device <deviceId>
Unset variable
particle env-vars unset <<KEY>> --device <deviceId>
Patch a list of elements
particle env-vars patch --device <deviceId> <envs.json>
example:
{ "ops": [ { "op": "set", "key": "KEY", "value": "value"] }
Outcome
-
--setshould creates or updates an existing key -
--unsetshould removes the env var or the overwrite -
--patchshould add every operation on the list - Re-running
env listconfirms the changes
3. Building using the --env flag
- Create a JSON env file:
{
"FOO": "123",
"BAR": "test"
}
- Add the following property to your project.properties file, referencing the env JSON file:
firmwareEnv=env.json
- Compile the project:
particle compile <platform>
Outcome
- CLI detects
firmwareEnvfield and bundles the binary - Inspecting the CLI should show the env-vars as asset and into their own section:
particle binary inspect <filename>
Related Issues / Discussions
Epic: https://app.shortcut.com/particle/epic/136671 Story details: https://app.shortcut.com/particle/epic/136671
Completeness
- [x] User is totes amazing for contributing!
- [x] Contributor has signed CLA
- [x] Problem and solution clearly stated
- [x] Tests have been provided
- [x] Docs have been updated
- [x] CI is passing