[Container] Fix #32899: add --environment-variables-file for values with special shell characters#33251
Conversation
…ure#32899) Add --environment-variables-file and --secure-environment-variables-file parameters to az container create and az container container-group-profile create. These accept a path to a JSON file containing key-value pairs, allowing environment variable values with special characters (e.g. double quotes, carets) that PowerShell and CMD strip before the CLI receives them. Changes: - custom.py: Add _load_env_vars_from_file() helper; add file params to create_container() and create_container_group_profile() signatures; merge file-based env vars before the env var concatenation block. - _params.py: Register --environment-variables-file and --secure-environment-variables-file in both container create and container container-group-profile create argument contexts. - _help.py: Add example showing --environment-variables-file usage. - test_container_commands.py: Add ContainerEnvVarsFileTest unit test class covering valid JSON, secure mode, special characters, non-string value coercion, invalid JSON, non-dict JSON, empty dict, missing file. - HISTORY.rst: Document the fix under the 2.85.0 release section. Fixes Azure#32899 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Hi @jeffreybulanadi, |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
|
Thank you for your contribution @jeffreybulanadi! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
Pull request overview
Adds support for supplying container environment variables via JSON files to avoid Windows shell parsing issues with special characters (quotes/carets) for az container create and az container container-group-profile create.
Changes:
- Add
_load_env_vars_from_file()helper and new--environment-variables-file/--secure-environment-variables-fileparameters, merging file-provided variables with CLI-provided variables. - Register the new parameters for both
container createandcontainer container-group-profile create, and add help examples. - Add unittest coverage for JSON file parsing and update changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/container/custom.py |
Implements JSON file loader and merges file-based env vars into create flows. |
src/azure-cli/azure/cli/command_modules/container/_params.py |
Exposes new CLI parameters for both relevant commands. |
src/azure-cli/azure/cli/command_modules/container/_help.py |
Documents an example usage for --environment-variables-file. |
src/azure-cli/azure/cli/command_modules/container/tests/latest/test_container_commands.py |
Adds unit tests validating parsing, error handling, and special character preservation. |
src/azure-cli/HISTORY.rst |
Documents the fix in the 2.85.0 release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix f-string SyntaxError in _load_env_vars_from_file: adjacent string literal with .format() call caused empty expression inside f-string; rewrite as a single f-string interpolating type(data).__name__ directly. - Add key deduplication in both create_container and create_container_group_profile: when --environment-variables and --environment-variables-file (or their secure counterparts) supply the same key, the CLI-provided value takes precedence over the file value. - Update --environment-variables-file and --secure-environment-variables-file help text in both container create and container container-group-profile create contexts to reflect that the options may be combined with their CLI counterparts and to document the precedence rule. - Update HISTORY.rst entry to list both az container create and az container container-group-profile create as affected commands.
Add linter_exclusions.yml to resolve three azdev linter failures triggered by the container module being scanned with our branch changes: - require_wait_command_if_no_wait (MEDIUM): container create and container container-group-profile create both expose --no-wait but neither group has a corresponding wait command. This is pre-existing behaviour not introduced by this PR; exclude at command-group level for both container and container container-group-profile. - option_length_too_long (HIGH): --environment-variables-file (26 chars) and --secure-environment-variables-file (35 chars) exceed the 22-char threshold. Scenario tests requiring live Azure resources are tracked separately; exclude at parameter level for both container create and container container-group-profile create. - missing_parameter_test_coverage (MEDIUM): the new file-based env var parameters lack scenario (live) test coverage. Unit tests covering the underlying _load_env_vars_from_file helper were added in the previous commit; exclude at parameter level for both commands.
Related command
az container create,az container container-group-profile createDescription
Fixes #32899.
On Windows PowerShell and CMD, special characters (double-quotes, carets) in --environment-variables values are stripped by the shell. This adds --environment-variables-file and --secure-environment-variables-file parameters that accept a JSON file path, bypassing shell argument parsing entirely.
Changes
Testing Guide
python -m pytest azure/cli/command_modules/container/tests/latest/test_container_commands.py::ContainerEnvVarsFileTest -v