Skip to content

az aks command invoke exits 0 when the command run in the cluster failsΒ #34496

Backlog

Description

Describe the bug

az aks command invoke exits with status 0 when the command it ran inside the cluster failed. The inner exit code is only printed (... with exitcode=1), so a script or CI job cannot tell that the command failed without parsing the output.

In a CI pipeline this produces a green run that did nothing: we had a bootstrap job where every kubectl apply sent through az aks command invoke was rejected with Forbidden, and all steps still passed.

Related command

az aks command invoke, az aks command result

Errors

None, which is the problem. The process exit status is 0 in all of these cases:

Result from the service What the CLI prints Process exit status
provisioningState=Succeeded, exitCode=0 ... with exitcode=0 + logs 0
provisioningState=Succeeded, exitCode=1 ... with exitcode=1 + logs 0
provisioningState=Failed command failed with reason: ... 0

Issue script & Debug output

az aks command invoke -g <rg> -n <cluster> --command "kubectl get nosuchresource"
echo $?   # 0

The cause is in _print_command_result in src/azure-cli/azure/cli/command_modules/acs/custom.py. It prints commandResult.exit_code (or commandResult.reason for a failed run) and returns, and neither aks_runcommand nor aks_command_result does anything else with the result. I confirmed this by calling _print_command_result directly with exit_code=1 and with provisioning_state="Failed": it returns None and raises nothing in both cases. The function is the same on dev today.

Expected behavior

The process exit status reflects the outcome, the way kubectl exec and ssh do:

  • inner command exited non-zero: exit with that code
  • run command itself failed (provisioningState=Failed): exit non-zero

Other modules already pass an inner exit code through, for example sys.exit(info.exit_code) in batchai/custom.py.

I understand changing the default could break scripts that rely on today's behaviour, so I see two options and am happy to implement whichever you prefer:

  1. Change the default and announce it through the breaking-change process.
  2. Add an opt-in flag (for example --propagate-exit-code) now, and consider changing the default later.

#25948 asks for the same thing for az vm run-command invoke.

Environment Summary

azure-cli 2.88.0 on macOS (Homebrew). Same code on dev.

Additional context

I can send a PR with tests once the approach is agreed.

Activity

  1. added
    bug
    on Nov 25, 2026
  2. added
    customer-reported
    Compute
    Azure CLI Team
    question
    AKS
    Service Attention
    Auto-Assign
    on Nov 25, 2026
  3. microsoft-github-policy-service commented on Nov 25, 2026

    @microsoft-github-policy-service
    Contributor

    Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc Drew McDaniel (@Drewm3), TravisCragg-MSFT (@TravisCragg-MSFT), nikhilpatel909, saraic (@sandeepraichura), Hilary Wang (@hilaryw29), GabstaMSFT (@GabstaMSFT), Raman Kumar (@ramankumarlive), ushnaarshadkhan, @Azure/act-observability-squad.

  4. removed
    Azure CLI Team
    question
    Compute
    on Nov 25, 2026
  5. yonzhan commented on Nov 25, 2026

    @yonzhan
    Collaborator

    route to service team

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AKSAuto-AssignService Attentionact-observability-squadbugcustomer-reported

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions