How to install managed package using Salesforce DX CLI?

I am trying to follow the Trailhead module on CI and Salesforce DX. I tried to push some of my Lightning components which depend on a managed package in App Exchange. I would like to know how to install a managed package using Salsforce DX CLI so that i can use that command in my travis.YML file for my CI integration.

Here is the script for my Travis file

sudo: true
dist: trusty
cache: false
env:
- URL=https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-
amd64.tar.xz
before_install:

- export SFDX_AUTOUPDATE_DISABLE=true
- export SFDX_USE_GENERIC_UNIX_KEYCHAIN=true
- export SFDX_DOMAIN_RETRY=300
- wget -qO- $URL | tar xJf -
- "./sfdx/install"
- export PATH=./sfdx/$(pwd):$PATH
- sfdx update
- sfdx force:auth:jwt:grant --clientid $CONSUMERKEY --jwtkeyfile 
assets/server.key
--username $USERNAME --setdefaultdevhubusername -a DevHub
script:
- sfdx force:org:create -f config/project-scratch-def.json -s -a 
PackageInstallation
- sfdx force:org:list
- sfdx force:org:display
- sfdx force:user:password:generate -u PackageInstallation
- sfdx force:org:display
- sfdx force:org:open -u PackageInstallation
- sfdx force:source:push -u PackageInstallation
- sfdx force:apex:test:run -u PackageInstallation -c -r human

I get the following error as my components depend on the app exchange components:

No COMPONENT named markup://ldt:datatableDev found :

Answer

This helped me get the right id for app exchange packages currently installed in my devhub:

$ sfdx force:package:installed:list -u [DevHubAlias]

=== Installed Package Versions [2]
ID                  PACKAGE ID          PACKAGE NAME           NAMESPACE  PACKAGE VERSION ID  VERSION NAME  VERSION
──────────────────  ──────────────────  ─────────────────────  ─────────  ──────────────────  ────────────  ────────
0A346000000qUm7CAE  03336000000DlP2AAK  HEDA                   hed        04t360000011zP6AAI  HEDA 1.43     1.43.0.3
0A346000000H6SeCAK  033C00000006mUuIAI  Apsona for Salesforce  apsona     04tC0000000ggXVIAY  Update        1.8.0.3

$ sfdx force:package:install -p 04t360000011zP6AAI -u scratch -w 5

Note: use the -p parameter instead of the old -i param.

Note: the HEDA package I am installing also required some additional setup in the scratch org before I could install it. Specifically I had to create a dummy account record type.

Attribution
Source : Link , Question Author : ak_1 , Answer Author : Theodoor

Leave a Comment