Azure / Azure/azure-cli

'az vm run-command create' fails with exitCode 3 and NO stdout/stderr if the bash command fails with non-zero exit code

Open
#26,677 2 comments 0 reactions 1 assignee Claimed by @zhoxing-ms View on GitHub
act-observability-squad Auto-Assign Auto-Resolve Azure CLI Team Compute customer-reported feature-request
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

'az vm run-command create' fails with exitCode 3 and NO stdout/stderr if the bash command fails with non-zero exit code. This makes it almost impossible to troubleshoot problems with bash commands running using this CLI. This is a portion of the output we get with a failing bash command:
```
"instanceView": {
"endTime": "2023-06-14T15:37:22+00:00",
"error": "",
"executionMessage": "Execution failed: failed to execute command: command terminated with exit status=-1",
"executionState": "Failed",
"exitCode": 3,
"output": "",
"startTime": "2023-06-14T15:37:21+00:00",
"statuses": null
}
```

And the problem can be reproduced on a Linux VM using the following commands:

```
az vm run-command create --resource-group ${RG} --location "West US" --script 'echo Hello; exit 5' --timeout-in-seconds 180 --run-command-name ${RUN_ID} --vm-name ${VM} --async-execution true --debug
az vm run-command show --resource-group ${RG} --run-command-name ${RUN_ID} --vm-name ${VM} --instance-view --debug
```

### Related command

az vm run-command create --resource-group ${RG} --location "West US" --script 'echo Hello; exit 5' --timeout-in-seconds 180 --run-command-name ${RUN_ID} --vm-name ${VM} --async-execution true

### Errors

Execution failed: failed to execute command: command terminated with exit status=-1

### Issue script & Debug output

{
"asyncExecution": true,
"errorBlobUri": null,
"id": "/subscriptions/d515653d-62b5-4cc8-a26c-8d098cce73cc/resourceGroups/sl-dev-d3dyobmeyupbzgsiktk72w-westus-rg/providers/Microsoft.Compute/virtualMachines/sl-dev-westus-vm-daa391f3-7/r unCommands/run18",
"instanceView": {
"endTime": "2023-06-14T15:37:22+00:00",
"error": "",
"executionMessage": "Execution failed: failed to execute command: command terminated with exit status=-1",
"executionState": "Failed",
"exitCode": 3,
"output": "",
"startTime": "2023-06-14T15:37:21+00:00",
"statuses": null
},
"location": "westus",
"name": "run18",
"outputBlobUri": null,
"parameters": null,
"protectedParameters": null,
"provisioningState": "Succeeded",
"resourceGroup": "sl-dev-d3dyobmeyupbzgsiktk72w-westus-rg",
"runAsPassword": null,
"runAsUser": null,
"source": {
"commandId": null,
"script": "echo Hello; sleep 3; echo Hello2",
"scriptUri": null
},
"tags": null,
"timeoutInSeconds": 180,
"type": "Microsoft.Compute/virtualMachines/runCommands"
}

### Expected behavior

We should see 'exitCode' as 5, 'output' as "Hello"

### Environment Summary

azure-cli 2.38.0 *

core 2.38.0 *
telemetry 1.0.6 *

Dependencies:
msal 1.18.0b1
azure-mgmt-resource 21.1.0b1

Python location '/usr/bin/python3.6'
Extensions directory '/home/azureuser/.azure/cliextensions'

Python (Linux) 3.6.8 (default, Aug 13 2020, 07:46:32)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.