Skip to content

{Packaging} Fix azps.ps1 wrapper to propagate exit codes and forward stdin#33260

Open
AaronRobinsonMSFT wants to merge 2 commits intoAzure:devfrom
AaronRobinsonMSFT:fix/azps-wrapper-issues
Open

{Packaging} Fix azps.ps1 wrapper to propagate exit codes and forward stdin#33260
AaronRobinsonMSFT wants to merge 2 commits intoAzure:devfrom
AaronRobinsonMSFT:fix/azps-wrapper-issues

Conversation

@AaronRobinsonMSFT
Copy link
Copy Markdown

Related command

azps.ps1 (Windows PowerShell wrapper installed by the MSI and available in the pip package)

Description

The azps.ps1 wrapper scripts had two minor issues previously discussed:

  1. Exit codes not propagated. The wrapper invoked python.exe -m azure.cli with & but never re-emitted $LASTEXITCODE. When the wrapper is invoked through pwsh.exe -Command (a very common pattern in CI), PowerShell only surfaces the script's exit code if the script itself calls exit N. As a result, failed CLI invocations appeared to succeed.
  2. Stdin not forwarded. Data piped into azps.ps1 was not passed through to the Python process, so any command that reads from stdin received nothing.

Fix

  • Pipe $input into the child python.exe invocation in both wrappers (build_scripts/windows/scripts/azps.ps1 for the MSI build, and src/azure-cli/azps.ps1 for pip).
  • Add an explicit exit $LASTEXITCODE at the end so the exit code surfaces correctly even under pwsh.exe -Command.
  • Add regression tests in build_scripts/windows/scripts/test_msi_installation.ps1 covering both the direct-invocation and pwsh.exe -Command paths.

Testing

New assertions in test_msi_installation.ps1 exercise:

  • azps.ps1 --version succeeds.
  • azps.ps1 <bad-command> returns a non-zero exit code (direct invocation).
  • pwsh.exe -NoProfile -Command "& azps.ps1 <bad-command>; exit $LASTEXITCODE" returns a non-zero exit code.

…stdin

The azps.ps1 wrapper scripts (both the MSI and pip variants) had two
minor issues:

1. Exit codes from the underlying python.exe invocation were not
   propagated, so callers (especially pwsh.exe -Command) would see a
   successful exit even when the CLI failed.
2. Stdin piped into the wrapper was not forwarded to the Python
   process, so commands that read from stdin did not receive input.

Pipe $input into the child process and add an explicit
`exit $LASTEXITCODE` at the end of both wrappers. Add regression
tests to test_msi_installation.ps1 to cover both behaviors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 00:13
@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 @AaronRobinsonMSFT,
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 24, 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>

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

This PR updates the Windows PowerShell azps.ps1 wrappers (MSI + pip) to better behave like a thin launcher for python.exe -m azure.cli, aiming to propagate the child process exit code and forward stdin for piped scenarios. It also adds MSI installation regression coverage for wrapper exit-code propagation.

Changes:

  • Pipe $input into the child python.exe invocation in both azps.ps1 wrappers and explicitly exit $LASTEXITCODE.
  • Add MSI installation regression tests validating azps.ps1 success and non-zero exit codes (direct + pwsh.exe -Command).
Show a summary per file
File Description
src/azure-cli/azps.ps1 Updates pip-installed wrapper to forward stdin and re-emit exit code.
build_scripts/windows/scripts/azps.ps1 Updates MSI wrapper to forward stdin and re-emit exit code.
build_scripts/windows/scripts/test_msi_installation.ps1 Adds MSI regression assertions for wrapper exit-code behavior.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 4

Comment thread src/azure-cli/azps.ps1
Comment thread build_scripts/windows/scripts/azps.ps1 Outdated
Comment thread build_scripts/windows/scripts/test_msi_installation.ps1
Comment thread src/azure-cli/azps.ps1 Outdated
- Only pipe $input into python.exe when the wrapper is actually
  receiving pipeline input ($MyInvocation.ExpectingInput). Otherwise
  invoke python.exe directly so interactive stdin is inherited from
  the console instead of being closed at EOF.
- Fix pre-existing 'Perfer' typo in src/azure-cli/azps.ps1.
- Harden the pwsh.exe -Command regression test: skip if pwsh.exe is
  unavailable, reset $global:LASTEXITCODE before the call, and also
  check $? so a command-not-found doesn't false-pass via a stale
  non-zero $LASTEXITCODE.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jiasli
Copy link
Copy Markdown
Member

jiasli commented Apr 24, 2026

Thanks for the contribution. There are actually more issues with ps1 as a wrapper that remain to be solved: #24015.

As previously discussed with PowerShell team, there is no plan to improve the ps1 as a wrapper behavior in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-platform-engineering-squad Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. Packaging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants