Installing managed packages to Scratch org via configuration

This should be possible with Second Generation Packaging. You can specify the dependencies of a package in the sfdx-project.json file.

In case you prefer to install the package in a script, you could do it like this:

#login to your DevHub
sfdx force:auth:jwt:grant --clientid [consumerKey] --username [devHubUserName] --jwtkeyfile assets/server.key --setdefaultdevhubusername

#create scratch
sfdx force:org:create -v [devHubUserName] -s -f [config/project-scratch-def.json] -a [scratchOrgName]

#push source to scratch
sfdx force:source:push -u [scratchOrgName]

#install package
sfdx force:package:install -i [packageId] -w 30 -u [scratchOrgName]

As example with the Salesforce CPQ 216.10.1 package, you can do the following.

  1. Create the force-app/main/default/installedPackages directory
  2. Create a file named SBQQ.installedPackage-meta.xml inside the new directory

The file you created should have the XML content below.

<?xml version="1.0" encoding="UTF-8"?>
<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <activateRSS>false</activateRSS>
    <versionNumber>216.10.1</versionNumber>
</InstalledPackage>

You can take a look at this super simple repo as a reference.


Not at present. Scripting the installations to happen after the scratch org has been created is the most appropriate way to do what you want today.