az vm run-command doesn't work in github actions

Viewed 99

I am trying to get the exit code as 0 or 1 from az vm run-command.

az vm run-command invoke -g myRG -n myVM --command-id RunShellScript --scripts "/home/azureuser/cassandra-script.sh" -o json | grep nodetool

but either my script succeeds or fails it gives the "$?" as 0. so decided to put " | grep xxxxx " but with this, it gives an error

`Error: Error: az cli script failed. cleaning up container... MICROSOFT_AZURE_CLI_1654967445460_CONTAINER

(node:1679) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)`

however, when I try to run the same command from azure cloud cli it works fine. but I want to use it in the GitHub actions pipeline Please help

1 Answers

If you are using Action Run Command, we have certain limitations.

The run-command requires port 443 connectivity. If the extension lacks access to these endpoints, the scripts may run successfully but fail to return results.

If you are using a Managed Run Command this allows us to run multiple scripts in parallel. But it is still in preview mode.

The az vm run-command invoke is working in Azure CLI but still have some bugs to run in pipelines. Refer the Az vm run-command invoke Github issue 1 & issue 2

Related