Skip to content

[Container] Fix #32899: add --environment-variables-file for values with special shell characters#33251

Open
jeffreybulanadi wants to merge 3 commits intoAzure:devfrom
jeffreybulanadi:fix/issue-32899-container-env-vars-special-chars
Open

[Container] Fix #32899: add --environment-variables-file for values with special shell characters#33251
jeffreybulanadi wants to merge 3 commits intoAzure:devfrom
jeffreybulanadi:fix/issue-32899-container-env-vars-special-chars

Conversation

@jeffreybulanadi
Copy link
Copy Markdown

Related command
az container create, az container container-group-profile create

Description

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

  • custom.py: Add _load_env_vars_from_file() helper; new params in create_container() and create_container_group_profile(); merge logic before env var concatenation.
  • _params.py: Register new args in both container create and container container-group-profile create contexts.
  • _help.py: Add example for --environment-variables-file.
  • test_container_commands.py: Add ContainerEnvVarsFileTest unit test class (8 tests).
  • HISTORY.rst: Document the fix under release 2.85.0.

Testing Guide
python -m pytest azure/cli/command_modules/container/tests/latest/test_container_commands.py::ContainerEnvVarsFileTest -v

  • The PR title and description has followed the guideline in Submitting Pull Requests.
  • I adhere to the Command Guidelines.
  • I adhere to the Error Handling Guidelines.

…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>
Copilot AI review requested due to automatic review settings April 23, 2026 12:18
@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Hi @jeffreybulanadi,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Breaking Change Starting...

Thanks for your contribution!

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Apr 23, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

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).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Apr 23, 2026
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

Thank you for your contribution @jeffreybulanadi! We will review the pull request and get back to you soon.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-file parameters, merging file-provided variables with CLI-provided variables.
  • Register the new parameters for both container create and container 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.

Comment thread src/azure-cli/azure/cli/command_modules/container/custom.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/container/_params.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/container/_params.py Outdated
Comment thread src/azure-cli/HISTORY.rst Outdated
- 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.
@yonzhan yonzhan assigned yanzhudd and unassigned zhoxing-ms Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Special characters (" and ^) are removed when passing environment variables via Azure CLI (PowerShell)

5 participants