Cli: force:mdapi:deploy sees a cancelled deployment as a success

Created on 22 Feb 2019  路  14Comments  路  Source: forcedotcom/cli

Summary

When deploying to an org with the force:mdapi:deploy command, if I cancel the deployment from inside the org then the CLI reports that as a successful deployment.

Steps To Reproduce:

  1. Deploy some source via force:mdapi:deploy and use the -w xx flag to wait for results.
  2. While the deploy is still running go into the org and cancel the deployment
  3. Check the exit code returned by SFDX it should return a status code "0" while also reporting "Status: Canceled"

Run the same steps for a deployment that fails for whatever reason (e.g. test code fails) and it returns a status code "1"

Expected result

Cancelled deployments should be considered a failed deployment and return a non-zero status code.

Actual result

Cancelled deployments are considered successful deployments and return a zero status code

Additional information

This is a particular issue in our CI system that when a deployment is cancelled it considers the run to be successful so we have incorrect tracking for what was deployed or not.

SFDX CLI Version:
sfdx-cli/6.53.0-67a9cbb60c (windows-x64) node-v8.9.4

SFDX plugin Version:
@salesforce/plugin-generator 1.0.1 (core)
@salesforce/sfdx-trust 2.0.1 (core)
builtins 1.0.0 (core)
salesforcedx 45.2.0 (core)

OS and version:
Windows 10 Pro, 1709

bug

Most helpful comment

Fixed in sfdx-cli 7.73.2 salesforcedx 49.9.2

All 14 comments

I think this is the intended experience because the deployment did not fail but was canceled instead. @kfidelak94's team owns this command, would it be helpful if the status code was just different then a successful build, i.e. if there was a canceled build status code?

@clairebianchi feels like you prematurely closed this out. This has real potential to F up CI processes and potentially break production orgs if one of these deployments slips through as "complete" when it really wasn't (speaking from experience).

@aheber Did you come up with some way to handle this?

In my case, I encountered a test error early on in the deployment and canceled it so I could make another attempt.

However, my CI process saw this as complete and continued with the rest of the process.

@ChuckJonas would adding a status code of canceled help?

@clairebianchi Do you mean I non-0 exit code or something else?

I'm using the --verbose format so it's easier to monitor the pipeline.

@ChuckJonas I haven't found a suitable action here. We have just had to be careful when we cancel.

I would still really like a non-0 exit code here. I'm fine if that code is 10 or 3000, just not 0.

@clairebianchi the primary users of an exit status are going to CI scripts, very dumb CI scripts. And those CI scripts like to do other stuff when something "succeeds", so if we return 0 when it's cancelled these dumb scripts will just keep doing whatever they were doing.

Bear in mind that most scripting are set up to chain things and this is all based on the return code (i.e. ./deploy.sh && ./merge.sh && ./launchNukes.sh or with most CIs they just stop on the first non-0 exit status). Returning something like a status value in json or some other form means you can't use any of this out of the box behavior.

Of course there could be a counter case, and would be curious to here if there are use cases where returning 0 for the status code is needed when a deployment is cancelled. @kfidelak94 anything you're aware of that would necessitate returning 0 for cancelled deployments?

Can confirm this is fucking us up here as well 馃憤

This just really f'd one of our orgs ORG up as an admin saw a test failure and canceled the deployment. The CI took this as "completed".

@kfidelak94 can we please get an update?

@ChuckJonas - thanks for the bump and apologies for the lack of communication on this issue. I agree that the command should not be returning a zero exit code since it didn't complete successfully. This is a bug and we'll expedite the fix, particularly due to the impact on production environments.

Thanks for the update @shetzel,

As a work around I figured out I could check the deploy status via JQ

DEPLOY_SUCCESS=$(sfdx force:mdapi:deploy:report -i $DEPOYMENT_ID --json | jq .result.success)
[ $DEPLOY_SUCCESS != 'true' ] && echo "Deployment Failed" && exit 1

Not sure how reliable this is, but at least now worst case is a successful deployment causes the CI to think it didn't deploy (which is much less impactful in our CI)

Fix should be in next week's patch release.

Fixed in sfdx-cli 7.73.2 salesforcedx 49.9.2

Though it's not mentioned in the release notes, the fix also works for sfdx force:source:deploy :)

Was this page helpful?
0 / 5 - 0 ratings