Think. Build. Salesforce Solutions.

Salesforce Consulting Services across Salesforce Clouds & Across App Lifecycles

Blog

Continuous integration using Jenkins

By |2020-07-16T05:43:07+00:00February 5th, 2016|

For administrators working with a single company, changesets are a great way to move updates between sandboxes and a parent org. However, when working on the enterprise tier, we often need to transfer components between various test and developer environments, which are outside the scope of changesets.

To support multiple developers working across multiple environments on various features and fixes, a proven path is to use an automated continuous integration system to simplify deployments and promote transparency.
Salesforce Jenkins

 

Continuous integration

The concept behind a continuous integration, or CI, tool is that a constant flow of development changes and unit testing will be done to detect conflicts and errors within the development cycle itself. It allows you to perform a baseline of quality assurance without much reliance on any manual processes (at least until you get that notification that your code just broke the build). The flow is something like:

Prerequisite Software

  1. Salesforce instance Source and destination cloud
  2. Eclipse with force.com IDE: This used to pull the desired code and components to be deployed at other Salesforce.com instances.
  3. GitHub repository as source control
  4. Jenkins: It controls the deployment
  5. JDK
  6. JRE
  7. Force.com Migration tool
  8. Apache Ant

Installation

1. Install ANT

1) Download and install JRE 6: Verify the correct installation by executing the following command: java version.
2)  Download and Install Ant (version 1.6 or higher) zip file from http://ant.apache.org/bindownload.cgi and set environment variable.
3) Download Force.com Migration Tool zip folder from Salesforce Org for which the path is as follows: Develop->Tools->Force.com Migration Tools.
4) Copy the “ant-salesforce.jar” file from the above extracted folder and paste it in the lib directory of the installed Ant folder.
5)  Set the environment Variables as follows:
->System Variables->new> Variable Name: ANT_HOME
Variable Value: C:\Program Files\apache-ant-x.xx.x
->System Variables->new> Variable Name: JAVA_HOME
Variable Value: C:\Program Files\Java\jdk1.8.0
->System Variables->edit->PATH ->In PATH, add %JAVA_HOME%\bin and %ANT_HOME%\bin….. SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;…. ;%JAVA_HOME%\bin;%ANT_HOME%\bin; …..
6)Verify if ‘C:\Program Files\Java\jdk_x.xx.x\lib’ contains ‘Tools.jar’ file.
7)Run the following command in cmd to verify the correct installation of ANT: ant -version
Update
sf.src = ../SFDC_CI_DEMO/src:
8) Update src path in build.xml and build.properties files.
Example: Please note that SFDC_CI_DEMO” is my project name created in eclipse.
In build.xml set basedir=”../SFDC_CI_DEMO/src” path at first line of code.
In build.properties set sf.src = ../SFDC_CI_DEMO/src” path at last line of code.
9) Install Eclipse with Force.com and Egit IDE (EGit IDE comes with eclipse. Check if it their else install GIT from Help -> Install new software

2.
Install GIT 

3. 
Install GITHUB (GitHubSetup.exe) “ This is required to install because if you are using public GitHub repository then you will have you use this to upload build.xml and build.properties files on cloud.
Note: Identify your GitHub repository and keep credentials and repository path handy. It will be required while pushing code from Eclipse to GitHub.

4.
Install Salesforce.com ANT Migration tool

5. Install Jenkins
You need to start Jenkins engine if you’ve installed using the .war file. To do this, open command prompt and navigate to the folder where ‘jenkins.war’ file is located. Run the following command:
C:/…>java -jar jenkins.war

If you’ve installed using the windows installer, there’s no need to start Jenkins engine.

To run Jenkins, open your browser and connect to ‘localhost:8080’ Once you see the message “Jenkins is fully up and running means you are ready to go on.
Now open the browser and enter http://localhost:8080/ . Configure Jenkins and configure Job to start using it.

Configuration

Configure Jenkins:

Once your Jenkins is up, goto jenkins > manage jenkins > configure system.
Update the JDK and ANT sections with their respective version and path.
Install GIT plugin from Manage Jenkin -> Manage plugins-> Available & choose GIT plugin to install.

Configure Job:

Go to http://localhost:8080/ and Click on Create New item (using Build a free-style software project option). Enter Item name (This is your project name example SFDC_Deployment) and save.
Select GIT from “Source Code Management section.
Enter Repository URL (Example https://github.com/ABCDEMO/ REPOSITORY1) and provide GITHUB repository password.
Goto ‘Build’ section in the configuration page. Select Ant version.
In the Targets field, enter the library and property file path.

Eg:
-lib
“C:\Program Files (x86)\apache-ant-1.9.2\lib\ant-salesforce.jar”
-Propertyfile
“D:\Users\Username\.jenkins\jobs\JenkinsJobName\workspace\CI\build.properties”
Click on advanced button. In the ‘Build File’ field, enter the the path Ant’s for build.xml

D:\Users\ Username \.jenkins\jobs\SFDC_Deployment\workspace\CI\build.xml

So here is the trick to get the best of out of these build.xml and build.properties files copied from Salesforce ANT tool installation Zip file. Update src path in build.xml and build.properties files.

Example: Please note that SFDC_CI_DEMO” is my project name created in eclipse.

In build.xml set basedir=”../SFDC_CI_DEMO/src” path at first line of code.
In build.properties  set .src = ../SFDC_CI_DEMO/src” path at last line of code.
After setting these paths, will upload these files to GitHub repository and then will sync it will local repository using GITHUB tool installed.
To do this you need to login into GITHUB local tool and navigate to your repository. Now go to settings and open in explorer. It open an explorer window. Create a folder named “CI” and then copy paste build.xml and build.properties updated files in this folder. Now check-in using GITHUB tool providing comment.

In the ‘Properties’ field, enter the salesforce parameters used by Ant in build.xml

sf.username = user@xyz.com
sf.password = PasswordSecurityToken
sf.serverurl = login.salesforce.com
sf.checkOnly = false
sf.runAllTests = false
sf.logLevel = none
Click Save. Your deployment job is ready to go!

We have seen all the technical details of setting up Jenkins that includes configuration of Jenkins and other software requirements.

Let’s see how to process this take the advantage of Jenkins. As discussed in the beginning, it starts with fetching the code in Eclipse.

Let’s start using Eclipse to fetch the code and components locally and to select the right code and components for deployment.
 
Using Eclipse to push code to the repository

1. Add a force.com project by giving the correct URL and credentials and download the project data at your local PC.
2. Now right click on the project name -> team -> share project
3. Select GIT from the popup window and click next.
4. Select a path (folder) on your system and click create repository”. It will create a local copy of the repository. Now finish closing the popup. Now you are ready with a local copy.
5. Now it’s time to push your code and deploy sfdc components to the cloud repository. (STEP 2 as per the image above)
6. To push your code and components right click on the project name then Team -> Commit. Before starting the deployment, we should know what we are going to deploy. Let’s say we take Classes, VF pages, Custom objects, Related page layouts, Custom profile, Report and Reports Types, and Workflows.
So, select the appropriate files and components to push to the repository and specify comment and click “Commit and Push. It will ask the repository URL and authentication details to push the code at the correct location. URL should end with git so copy and paste proper URL from the repository. Example https://github.com/ABCDEMO/ REPOSITORY1.git

Note: ANT checks package.xml of the project src file to know what all things have to migrate. So on every change org check-in, this updated XML should be checked into the repository as well.

So now your selected code is pushed to repository and Jenkins is already configured. In Jenkins we have not given any time period to start the build process automatically, it will not start the build automatically. We have to build manually as per convenience. To build the build go to Jenkins’s job & click ‘Build Now’ to run the deployment job.

To configure Jenkins auto-build the changes pushed in source control at any given time we can configure Jenkins by defining it at Build Triggers section in Poll SCM field. If we want that Jenkins should try to build after every 15 min., then we will write H/15 * * * *

20 Comments

  1. EthanHoath September 4, 2019 at 6:59 pm - Reply

    Great post\Nice post, I like it so much. I was very lucky to discover your site. It’s got so much useful information!

    • MirketaInc August 12, 2020 at 8:20 am - Reply

      Happy to help you, EthanHoath

  2. DanielSaund September 6, 2019 at 12:04 pm - Reply

    I enjoy all your posts. You’ve done a great job

    • Mirketa Inc August 12, 2020 at 8:22 am - Reply

      Thanks so much

  3. Martinsic June 21, 2020 at 9:02 pm - Reply

    It is very nice to read your site, thank you very much for your work, it’s great!

    • Mirketa Inc August 12, 2020 at 8:24 am - Reply

      Thanks for the feedback, Martinsic

  4. wewly July 14, 2020 at 8:15 pm - Reply

    I am very interested in this topic and glad to find some information about it here.
    In this website there is also a lot of interesting and useful information:

    • Mirketa Inc August 12, 2020 at 8:25 am - Reply

      Happy to help!

  5. Gust August 5, 2020 at 10:57 am - Reply

    You are my inspiration, I have few blogs and occasionally run out from post :).

    • Mirketa Inc August 12, 2020 at 8:26 am - Reply

      Thanks

  6. Vidus August 8, 2020 at 4:21 am - Reply

    Dear buddies, just came across this amazing blog and would like to post some handy software resource which might be help, thanks!

    • Mirketa Inc August 12, 2020 at 8:28 am - Reply

      Thanks for the feedback

  7. wewly August 9, 2020 at 10:22 pm - Reply

    I really cannot add more to what was said because you have disclosed all important information. I must say that this site is quite nice.
    In this website there is also a lot of interesting and useful information:

    • Mirketa Inc August 12, 2020 at 8:29 am - Reply

      Thanks so much. Wewly. We appreciate the kind words and support.

  8. Davis August 11, 2020 at 11:27 pm - Reply

    I got what you intend,saved to fav, very nice web site.

    • Mirketa Inc August 12, 2020 at 8:30 am - Reply

      Thank you, Davis

  9. Roma August 17, 2020 at 7:46 pm - Reply

    Hello There. I discovered your blog the usage
    of msn. This is an extremely smartly written article.

    I’ll make sure to bookmark it and come back to learn more of your helpful information. Thanks
    for the post. I will definitely comeback.

    • Mirketa Inc September 2, 2020 at 6:07 am - Reply

      Thanks, Roma. We appreciate the kind words.

  10. Flvtoch August 29, 2020 at 9:31 pm - Reply

    Hi there, just visited your excellent articles, really appreciate your works!

    • Mirketa Inc September 2, 2020 at 6:06 am - Reply

      You’re welcome

Leave A Comment