[SalesForce] Installing managed packages to Scratch org via configuration

We've recently started adopting Salesforce DX and we're trying to figure out the best way to spin up Scratch orgs.

As of now, we have multiple managed packages from the AppExchange installed in production, including Marketing Cloud Connect and Cirrus Insight and we would like to make certain scratch orgs have them.

I know there is a way to install packages with the sfdx force:package:install command, but is there any way to do it via configuration so that we don't have to execute a certain set of commands everytime we create a scratch org?

Thanks!

Best Answer

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]
Related Topic