Jenkins Setup for Salesforce.com Automated Deployment

Continuous Integration (Build automation) for salesforce.com using GitHub repository: Step by Step by Jenkins Setup

I did a small POC for Jenkins setup to automate the build deployment (Continuous Integration) of SFDC and GitHub as repository on cloud. 
I thought to share my experience.

To start with let’s first understand the basics and approach I took to achieve this.

Following are the major components are involved to make it happen. These are not software requirement. Software requirements are defined later in this article.
1.                  Salesforce instance – Source e.g.: Dev Sand Box where the configuration and customization has been done.
2.                  Eclipse with force.com IDE: This used to pull the desired code and components to be deployed at other Salesforce.com instance.
3.                  GitHub repository as source control
4.                  Jenkins : It control the deployment
5.                  Salesforce-Ant build tool


6.                   Salesforce instance – destination cloud



Overview of Build Automation with Jenkins:
So as the image describes, before getting into Jenkins, we should have our code checked-in/pushed in GITHUB Source Control repository. In order to do that, we will use Eclipse to identify correct files and components to deploy and then we psh the same.
Software Requirements:

  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 instance.
  3. GitHub repository as source control
  4. Jenkins : It control the deployment
  5. JDK
  6. JRE
  7. Force.com Migration tool
  8. Apache Ant
 Installation: 

1.             Install ANT
a.            Download and install JRE 6 : Verify the correct installation by executing the following command: java -version
b.            Download and Install Ant(version 1.6 or higher) zip file fromhttp://ant.apache.org/bindownload.cgi and set environment variable
c.             Download Force.com Migration Tool zip folder from Salesforce Org for which the path is as follows: Develop->Tools->Force.com Migration Tools
d.            Copy the "ant-salesforce.jar" file from the above extracted folder and paste it in the lib directory of the installed Ant folder.
e.            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; .....

f.              Verify if 'C:\Program Files\Java\jdk_x.xx.x\lib' contains 'Tools.jar' file.
g.            Run the following command in cmd to verify the correct installation of ANT : ant -version
Update 
sf.src = ../SFDC_CI_DEMO/src:
h.            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. 

i.              Install Eclipse with Force.com and Egit IDE (EGit IDE comes with eclipse. Check if it there else install GIT from Help -> Install new software

2.             Install GIT (example Git-x.x.x-preview20xxxxxx.exe)
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
If you're running on Windows you might want to run Jenkins as a service so it starts up automatically without requiring a user to log in. Install jenkins using windows package (http://jenkins-ci.org/) or using java web archive (.war) file.
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 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.

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 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 “sf.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 a 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 'Proprties' 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 requirement.

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

Let’s start using Eclipse to fetch the code and components locally and to select right code and components for deployment.
I am assuming that you have Eclipse with Force.com IDE is already installed. (If it not installed please refer below section).

Using Eclipse to push code to repository
1.       Add a force.com project by giving 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 pop up 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 pop up. Now you are ready with a local copy.
5.       Now it’s time to push your code and deploy sfdc components to cloud repository. (STEP 2 as per 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 that 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 repository and specify comment and click “Commit and Push”. It will ask repository URL and authentication details to push the code at correct location. URL should end with git so copy and paste proper URL from 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 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 job & click 'Build Now' to run the deployment job.

To  configure Jenkins to 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 * * * *


I hope this would help you. Please feel free to post errors, questions and comments. I will try to provide a solution as per my experience with it.

Thanks,
Javed Nehal Jamali



Comments

  1. Great post, Javed.
    As usual.. Thorough and detailed! Thanks for documenting this!

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Hi Javed,

    I have a question, if we schedule automatic deployments, can Jenkins only pick the changed or added metadata from salesforce?

    ReplyDelete
  4. Thanks for this blog. All screenshots can explain the full blogs easily. This is very easy to understand. Using this screen shots know the details becomes easy.
    Web Designing Training

    ReplyDelete
  5. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to our mind.As always, we appreciate your confidence and trust in us.
    Best Java J2ee training institutes in chennai



    ReplyDelete
  6. your information is really awesome as well as it is very excellent and i got more interesting information from your blog.Android Training in Chennai

    ReplyDelete
  7. Your thinking toward the respective issue is awesome also the idea behind the blog is very interesting which would bring a new evolution in respective field. Thanks for sharing.

    Informatica Training in Chennai

    Dataware Housing Training in Chennai

    ReplyDelete
  8. This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.Your final conclusion was good. We are sowing seeds and need to be patiently wait till it blossoms.

    Painless Dental Treatment In Chennai

    Best Dental Clinic In Adyar

    ReplyDelete
  9. Thank you for providing this details here. I am looking forward for further information regarding Digital marketing.



    SEO Company in India

    ReplyDelete




  10. تعد عملية التنظيف من اهم الخدمات التي يجب ان تكون متوفره دوما ليساعدنا علي حياه افضل لنا جميعا ولكي تتم علي اكمل وجه يجب الاستعانه بمتخصصين في هذا المجال
    تنظيف مساجد بالرياض
    نظرا لما يمتلكون من ادوات وسبل للوصول لاعلي مستوي نظافه ممكن

    ReplyDelete
  11. Your information is really awesome as well as it is very excellent and i got more information about CRM Software from your blog.

    ReplyDelete
  12. Could you please share a video and build.xml file and build.properties file, it will help a lot more.

    It is bit urgent could you please share.

    ReplyDelete
  13. I do agree with all the ideas you have presented in your post. They’re really convincing and will certainly work. Still, the posts are very short for newbies. Could you please extend them a little from next time? Thanks for the post..
    Barcode Solutions
    Athletic Management Software
    Barcode Solutions provider in Chennai

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. crm care

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. This comment has been removed by a blog administrator.

    ReplyDelete
  18. Great!!post Thanks for sharing this article information.It is very useful for creating blogs.Jenkins Setup information about understand easy language.
    crm software

    ReplyDelete

Post a Comment

Popular posts from this blog

Cloud based CRMs (Dynamics CRM v.s. Salesforce) -Part 2

Dynamics 365 Customer Engagement Queues and getting the best out it.