Configure Your Environment for Jenkins
Before integrating your Dev Hub and scratch orgs into your existing Jenkins framework,
configure your Jenkins environment. Our example assumes that you’re working in a package
development model.
-
In your Dev Hub org, create a connected app as described by the JWT-based authorization flow. This step includes obtaining or creating a private key and digital certificate.
Make note of your consumer key (sometimes called a client ID) when you save the connected app. You need the consumer key to set up your Jenkins environment. Also have available the private key file used to sign the digital certificate.
-
On the computer that’s running the Jenkins server, do the following.
- Download and install Salesforce CLI.
-
Store the private key file as a Jenkins Secret File using the Jenkins Admin Credentials
interface. Make note of the new entry’s ID.
You later reference this Credentials entry in your Jenkinsfile.
-
Set the following variables in your Jenkins environment.
- SF_USERNAME—The username for the Dev Hub org, such as juliet.capulet@myenvhub.com.
- SF_INSTANCE_URL—The login URL of the Salesforce instance that hosts the Dev Hub org. The default is https://login.salesforce.com. We recommend that you update this value to the My Domain login URL for the Dev Hub org. You can find an org’s My Domain login URL on the My Domain page in Setup.
- SF_CONSUMER_KEY—The consumer key that was returned after you created a connected app in your Dev Hub org.
- SERVER_KEY_CREDENTALS_ID—The credentials ID for the private key file that you stored in the Jenkins Admin Credentials interface.
- PACKAGE_NAME-The name of your package, such as My Package.
- PACKAGE_VERSION-The version of your package, which starts with 04t.
- TEST_LEVEL-The test level for your package, such as RunLocalTests.
The names for these environment variables are just suggestions. You can use any name as long as you specify it in the Jenkinsfile.You can also optionally set the SF_AUTOUPDATE_DISABLE variable to true to disable auto-update of Salesforce CLI. CLI auto-update can interfere with the execution of a Jenkins job.
- Set up your Salesforce DX project so that you can create a scratch org.
- (Optional) Install the Custom Tools Plugin into your Jenkins console, and create a custom tool that references Salesforce CLI. The Jenkins walkthrough assumes that you created a custom tool named toolbelt in the /usr/local/bin directory, which is the directory in which Salesforce CLI is installed.