Cli-microsoft365: O365 CLI doesn't return non-zero exit code on failed commands

Created on 5 Sep 2019  路  8Comments  路  Source: pnp/cli-microsoft365

TL;DR

When login fails, the CLI exit with an error code (1). Apparently it doesn't do that in v2... in fact, it seems like other commands (uploading app package & deploying), when they fail, aren't existing with a non-zero return code.

Expected Behavior

When a CLI command fails, the CLI returns a non-zero exit code.

Observed Behavior

When a CLI command fails, the CLI returns a zero exit code, indicating the process completed successfully, even when the command fails.

I only checked three commands:

  • o365 login
  • o365 spo app add
  • o365 spo app deploy

Background

Noticed this in my CI/CD automation. I use the CLI for uploading & deploying SharePoint packages to SPO. Everything was working fine until today when my deploy steps were hanging and eventually timing out.

Inspection of the logs traced back to a failed login as I was using the v1 vs newer v2 CLI syntax (*I was using the o365 spo login .. instead of o365 login ..), but the step wasn't failing. Steps fail in CD when they detect a non-zero exit code from the command.

The following image shows a failed login from the logs, BUT notice the green arrow where the task is not recognized as failing. I noticed the same thing where the upload step (o365 spo add app ...) was also failing in the logs, but the step wasn't seen as a failed step.

image

Another example from uploading & deploying an app package... notice the first one is even failing (node.js error) but green status text indicates the process was successful, same with the check in the top right.

image

bug work in progress

All 8 comments

Thanks for reporting it. This is definitely not intentional and the CLI should be returning non-zero exit codes when a command fails. One of the things that heavily relies on this capability is the Starter Kit provisioning script. I'll have a look at it asap to see if there are some edge cases that we might have missed. Sorry for the trouble.

When I run o365 spo login, you indeed get a 0 exit code. That is an error that we should fix, ie. CLI should return a non-zero code when trying to run non-existent commands.

When you run a command like o365 spo web get -u https://contoso.sharepoint.com, which leads to an error, you get a non-zero exit code, so this is correct.

I also noticed, that when you're not authenticated and try to run a command which requires it, instead of throwing an error, we're issuing a login prompt which shouldn't be the case. So it's another bug that slipped through our fingers.

1097 solves the issue of trying to execute a non-existent command returns a zero exit code

Awesome... nice quick work!

1098 fixes the other part of the issue where for some reason we allowed SPO commands to be executed without having to log in to O365 first. That's fixed now so with the next beta, all should work as expected.

...or not work when expected ;)

Exactly! 馃憤

Fixes are available in the latest beta which you can get @ @pnp/office365-cli@next. Once again thank you for spotting and reporting the issue 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

waldekmastykarz picture waldekmastykarz  路  3Comments

arjunumenon picture arjunumenon  路  3Comments

garrytrinder picture garrytrinder  路  3Comments

VelinGeorgiev picture VelinGeorgiev  路  3Comments

andrewconnell picture andrewconnell  路  3Comments