This guide outlines the steps to integrate Jenkins, a popular automation server, with Salesforce, a leading CRM platform. By integrating Jenkins with Salesforce, you can automate various tasks like testing and source code deployment from one org to another.
- Jenkins: Ensure Jenkins is installed and running on your system.
- Salesforce: Have access to a Salesforce Developer Hub org and necessary permissions to create Connected Apps.
- GitHub: Have your Salesforce project hosted on GitHub for version control.
-
Create Connected App for JWT-Based Flow:
- Log in to your Salesforce Developer Hub org.
- Navigate to Setup > App Manager > New Connected App.
- Fill out the required information, including Callback URL (can be any valid URL), and enable OAuth settings.
- Make sure to select "Use digital signatures" and "Enable for Device Flow" checkboxes.
- Save the Connected App and note down the Consumer Key.
-
Configure Environment Variables in Jenkins:
- Set the following environment variables in Jenkins:
- SF_USERNAME: The username for the Salesforce Developer Hub org.
- SF_INSTANCE_URL: The login URL of the Salesforce instance that hosts the Dev Hub org. Update to My Domain login URL if applicable.
- SF_CONSUMER_KEY: The Consumer Key generated for the Connected App.
- SERVER_KEY_PASSWORD: The password used to encrypt the server.key.enc file.
- Set the following environment variables in Jenkins:
-
Download Salesforce CLI in Jenkins User:
- Switch to the Jenkins user:
sudo -su jenkins
- Install Node.js and npm:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - &&\ sudo apt-get install -y nodejs
- Install Salesforce CLI:
npm install @salesforce/cli --global
- Switch to the Jenkins user:
- Generate SSH key pair in Jenkins:
- Switch to Jenkins user.
- Generate SSH key pair using
ssh-keygen
.
- Add SSH public key to GitHub:
- Copy the public key generated in the previous step.
- Add it to your GitHub account's SSH keys.
- Test the SSH connection:
- Run
ssh -T [email protected]
to verify the SSH connection to GitHub.
- Run
- Add New Item:
- Go to Jenkins Dashboard and click on New Item.
- Provide the project name and select the type of project as Multibranch.
- Add Source:
- Provide the repository URL and configure branch sources.
- Start a Build:
- Trigger a build to test the Salesforce integration.