[SalesForce] Deploy from Sandbox to Production Org SFDX

I created an SFDX project with manifest in VSCODE, authorized my sandbox org and retrieved source from manifest on the default package.xml. At this point I had the base setup with classes, triggers, aura etc.. I only made a change to a class file, right click deploy source to org which deploys to my sandbox. Now I want to deploy to my production org, but I get the following error sf:INVALID_OPERATION: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations

How can I deploy this file to production?

Best Answer

As of Now

You can use sfdx force:source:deploy -l RunLocalTests ... to run tests. This will enable deploying source-formatted metadata directly to production.


Original Answer

As of Spring '19

force:source:deploy doesn't support deploying to production, as it always specifies to run no tests, and tests are required for deployment to production. You can either use unlocked packages force:package:install, or you can use force:source:convert followed by force:mdapi:deploy to deploy to production.


Note to future visitors: This feature may have been added after this answer was written. Be sure to check the documentation.