particle-cli icon indicating copy to clipboard operation
particle-cli copied to clipboard

Feature/sc 136671/env vars

Open hugomontero opened this issue 1 month ago • 0 comments

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.properties field named firmwareEnv referencing one or more env-var files.
    • OR the user provides an explicit --env <path> flag during bundling.
  • 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

  • --set should creates or updates an existing key
  • --unset should removes the env var or the overwrite
  • --patch should add every operation on the list
  • Re-running env list confirms the changes

3. Building using the --env flag

  1. Create a JSON env file:
{
  "FOO": "123",
  "BAR": "test"
}
  1. Add the following property to your project.properties file, referencing the env JSON file:
firmwareEnv=env.json
  1. Compile the project: particle compile <platform>

Outcome

  • CLI detects firmwareEnv field 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

hugomontero avatar Dec 01 '25 23:12 hugomontero