I am running my sfdx deploy command in a shell script as part of a Github action. Currently, the script is reporting success even if the sfdx command fails. This means the build is succeeding even when it fails.

How can I query the result of the sfdx command (force:source:deploy with tests run) and fail the script and have a failed build reported when the deploy command fails?

Here are the lines of code in my shell script:

sfdx force:source:deploy -x $DEPLOY_FOLDER/package/package.xml --verbose -c -l RunSpecifiedTests -r $testsToRun
echo -e "Deployment to [$targetEnv] successful."

And here is the end of the output from the script as seen in Github:

ERROR running force:source:deploy:  Deploy failed.
----> Deployment to [localBuild] successful.

Thanks in advance, Peter

  • 2
    Have you tried testing the exit code returned by the sfdx command or using conditional command chaining? This is more a question around shell scripting than Salesforce, so probably should be posted elsewhere...
    – Phil W
    Jan 12 at 11:06

1 Answer 1


Thanks Phil W for your comment. I am inexperienced in Shell scripting and was unaware of the generic exit code. I posted here thinking I needed to know how to determine specific error details of the sfdx command.

I used the following code to now correctly determine the result of the sfdx command.

sfdx force:source:deploy -x $DEPLOY_FOLDER/package/package.xml --verbose -c -l RunSpecifiedTests -r $testsToRun
if [ "$?" -ne "0" ]; then
    echo -e "$RED_TEXT----> Deployment to [$targetEnv] FAILED."
    exit 1
echo -e "$GREEN_TEXT----> Deployment to [$targetEnv] successful."

Not the answer you're looking for? Browse other questions tagged or ask your own question.