2

In a DevOps chain, I have a SFDX project.

I want to deploy only parts of this SFDX Project to an org, using a custom package.xml

My actions are :

  • sfdx force:source:convert -d tmp/deployDemoQuali/
  • replace tmp/deployDemoQuali/package.xml by my own custom package.xml
  • sfdx force:mdapi:deploy -d tmp/deployDemoQuali/ -w 60 -u DemoQuali

Problem is that even with filtered package.xml, fdx force:mdapi:deploy seems to take the full content of tmp/deployDemoQuali/

How can I filter content of tmp/deployDemoQuali/ to keep only the items listed in my custom package.xml ?

Thanks ! :)

  • Isn't this a defect of sfdx force:mdapi:deploy? There's a major inconsistency with the --zipfile option. sfdx expects the zipfile and package file to match 1:1. This causes a problem if I only want to deploy a single class from my project and not the entire contents of package.xml. This is not how ant migration is implemented. With the migration tool I can create a zipfile containing only a single class and the /entire/ package.xml and only the class deploys. sfdx force:mdapi:deploy complains for every missing item from the package. Is this the same problem you're experiencing? – tggagne Oct 17 '18 at 10:59
  • it's exactly that: if the folder or zipfile doesn't contain exactly the content described in package.xml file, you have an error. Use of sfdx-essentials plugin will make this problem disappear :) – Nicolas Vuillamy Oct 18 '18 at 12:36
5

So ... I finally created a sfdx plugin allowing to do that

https://github.com/nvuillam/sfdx_metadatas_filtering

  • Install it

    sfdx plugins:install sfdx_metadatas_filtering

  • Use it

    sfdx metadatafilter:execute -i mdapi_output_dir -p myPackage.xml -o md_api_filtered_output_dir

Full example

sfdx force:source:convert -d tmp/deployDemoQuali/
sfdx metadatafilter:execute -i tmp/deployDemoQuali/ -p myPackage.xml -o tmp/deployDemoQualiFiltered/
sfdx force:mdapi:deploy -d tmp/deployDemoQualiFiltered/ -w 60 -u DemoQuali

Warnings:

  • all cases are not taken in account yet, please read carefully the README and contribute if you are in a hurry :)

  • Windows users: sfdx plugin generator is bugged on windows (hardcode call of linux rm instruction) , so you may use Git Bash to run this code ( at least while it installs the plugin dependencies )


EDIT 26/06/2018

It seems that several plugins are necessary to survive in this cruel world, so I joined all the ones I needed to create (including metadata filtering) into https://github.com/nvuillam/sfdx-essentials

This is the only maintained plugin , please use it :)


  • I made my first working deployment using v 0.7.2 of the plugin, it's ready to use :) – Nicolas Vuillamy Jun 6 '18 at 7:39
0

The approach I have taken is to use Ant's very flexible file matching to filter the set of components into a separate folder and then run the sfdx force:source:convert on that folder:

<target name="convert">
    <copy todir="./mdapi-source/staged">
        <fileset dir="./sfdx-source/int/test"/>
        <fileset dir="./sfdx-source/int/main"/>
        <fileset dir="./sfdx-source/wiz/test">
           <exclude name="**/aura/**"/>
           <exclude name="**/staticresources/**"/>
        </fileset>
        <fileset dir="./sfdx-source/wiz/main"/>
    </copy>
    <exec dir="." executable="sfdx" osfamily="unix" failonerror="true">
        <arg value="force:source:convert"/>
        <arg value="--rootdir" />
        <arg value="./mdapi-source/staged" />
        <arg value="--outputdir" />
        <arg value="./mdapi-source/cvux" />
    </exec>
</target>

leaving sfdx force:mdapi:deploy to figure out its own package.xml.

If you prefer some other scripting language, you can accomplish the same thing in that.

  • my custom package.xml contains exactly what I want to deploy ... with your solution, I can't use it and I must write an ant copy task to manually filter all its content ? :/ this seems long ... i'm more looking for a "ready to use" solution :/ – Nicolas Vuillamy May 26 '18 at 12:13
  • @NicolasVuillamy I don't think compatibility with package.xml is a priority in the newer sfdx tools. If there isn't one already - someone else may know of one - then you could write your own as sfdx is open for extension and share with the wider community. – Keith C May 26 '18 at 13:14
  • yipee, I have to work for Salesforce for free to solve a lack in their functions :) Meanwhile ... as I don't have the time, I'll probably deploy in a scratch, then make a mdapi:retrieve with my package.xml, then use it for demployment .... Ugly, but it should work – Nicolas Vuillamy May 26 '18 at 17:39
  • @NicolasVuillamy Keep checking back here though: someone may know a direct answer to the question. (I mentioned being able to add to the tooling because closed tooling is even worse where you have to bodge something on the side.) – Keith C May 26 '18 at 18:15
  • Started to do a plugin .... no time to wait for SFDC, but i'm still angry ;) Thanks for the tip about the plugin generator :) github.com/nvuillam/sfdx_metadatas_filtering , prototype works for some of the first metadatas, will complete it tomorrow – Nicolas Vuillamy May 28 '18 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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