sfdx-travisci-package
For a fully guided walkthrough of setting up and configuring continuous integration using scratch orgs and Salesforce CLI, see the Continuous Integration Using Salesforce DX Trailhead module.
This repository shows one way you can successfully use scratch orgs to create new package versions with Travis CI. We make a few assumptions in this README. Continue only if you have completed these critical configuration prerequisites.
- You know how to set up your GitHub repository with Travis CI. (Need help? See the Travis CI Getting Started guide.)
- You've installed the Travis CLI.
- You have properly set up JWT-based authorization flow (headless). We recommend using these steps for generating your self-signed SSL certificate.
Getting Started
-
Make sure that you have Salesforce CLI installed. Run
sfdx force --help
and confirm you see the command output. If you don't have it installed, you can download and install it from here. -
Fork this repo to your GitHub account using the fork link at the top of the page.
-
Clone your forked repo locally:
git clone https://github.com/<git_username>/sfdx-travisci.git
-
Setup a JWT-based auth flow for the target orgs that you want to deploy to. This step creates a
server.key
file that is used in subsequent steps. (https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_jwt_flow.htm) -
Confirm that you can perform a JWT-based auth:
sfdx force:auth:jwt:grant --clientid <your_consumer_key> --jwtkeyfile server.key --username <your_username> --setdefaultdevhubusername
Note: For more info on setting up JWT-based auth, see Authorize an Org Using the JWT-Based Flow in the Salesforce DX Developer Guide.
-
From your JWT-based connected app on Salesforce, retrieve the generated
Consumer Key
. -
Set your
Consumer Key
andUsername
using the Travis CLI. Note that this username is the username that you use to access your Dev Hub.travis env set USERNAME <your_username> travis env set CONSUMERKEY <your_consumer_key>
-
Locate the generated
server.key
and keep track of its location. -
Open the
.travis.yml
file and remove the first line that starts withopenssl ...
, then save the file. -
From the root folder of your local project, encrypt your
server.key
value:cd your_project_location
travis encrypt-file your_key_location/server.key assets/server.key.enc --add
This step replaces the existing
server.key.enc
with your encrypted version. -
Copy all the contents of
package-sfdx-project.json
intosfdx-project.json
and save. -
Create the sample package running this command:
sfdx force:package:create --path force-app/main/default/ --name "Travis CI" --description "Travis CI Package Example" --packagetype Unlocked
-
Create the first package version:
sfdx force:package:version:create --package "Travis CI" --installationkeybypass --wait 10 --json --targetdevhubusername HubOrg
-
In the
.travis.yml
: Update the value in thePACKAGENAME
variable to be Package ID in yoursfdx-project.json
file. This ID starts with0Ho
. -
Commit the updated
.travis.yml
,server.key.enc
, andsfdx-project.json
files.
Now you're ready to go! When you commit and push a change, your change kicks off a Travis CI build.
Enjoy!
Contributing to the Repository
If you find any issues or opportunities for improving this repository, fix them! Feel free to contribute to this project by forking this repository and making changes to the content. Once you've made your changes, share them back with the community by sending a pull request. See How to send pull requests for more information about contributing to GitHub projects.
Reporting Issues
If you find any issues with this demo that you can't fix, feel free to report them in the issues section of this repository.