Sunday, February 13, 2022

Unexpected behavior when using -p twice with sfdx (Salesforce CLI)

This is kind of a lesson about not assuming a program behavior.

I had 2 metadata items to deploy: one trigger, one custom metadata.  I was working on the trigger first, and had been using this command to deploy it and bang it against different orgs.

sfdx force:source:deploy -u qa -p ./force-app/main/default/triggers/TaskTrigger.trigger -c -l RunSpecifiedTests -r TaskTriggerTest

When I decided to also add changes to the custom metadata, I just added the second file as an additional param instead of back cursor the command to modify it (lazy, I know), so the command became

sfdx force:source:deploy -u qa -p ./force-app/main/default/triggers/TaskTrigger.trigger -c -l RunSpecifiedTests -r TaskTriggerTest -p ./force-app/main/default/customMetadata/Feature_Setting.TaskTrigger.md-meta.xml

Here's where the trouble began.  The command seemed to run just fine, but slowly I noticed the changes (which were simple) just didn't seem to stick and show up in the test run, after having a few puzzling run results and checking debug log.  It was as if that the command deployed the files, and then decided to run the tests with the old file versions.  When I switched to using -x and list the 2 files in a manifest file, and all was well as expected. 

It seems to be a completely unexpected (and undocumented AFAIK) behavior, but, in the end, I only had myself to blame to stumble on it.  🤷

For the record, my sfdx was 7.137.1.


No comments:

Post a Comment