Raushan Kumar
7 min readJul 5, 2020

Step By Step CI/CD Setup for Salesforce using Jenkins, GITHUB and VS Code

This is the final blog of the Version Controlling system, if you are reading this blog for the first time. I would suggest you check my previous 2 blogs on version control. Please find the link below

Part 1

https://medium.com/@raushansingh184/version-control-implementation-on-sfdc-7e4c94731b6d

Part 2

https://medium.com/@raushansingh184/part-2-version-controlling-in-salesforce-9055c30494a6

Before Implementing CI/CD. Let’s Understand what is CI/CD i.e continuous Integration and Continuous Development.

Suppose you are working in an organisation where being a developer your task is to build the new features, perform unit testing and push it to your Git Repository or any other repository. As the next step, you deploy your code to QA or any other testing sandbox where these codes can be tested with complete organization code. If QA finds any error while testing the code, it again comes back to the developer. This circle of process is known as Continuous Integration and Continuous Development.

But the limitations of the above process is that it requires a lot of manual effort and is prone to errors. So considering these issues and challenges, People thought of automating the whole CI and CD Process to decrease the manual intervention. Now Imagine, as a developer you just have to push your code to GIT HUB and your whole CI/CD process will be initiated automatically, like your code will be pushed automatically to the destination org, your test classes will run automatically, if any error then you will be notified via email and you can work on those errors. Automating CI/CD has helped a lot of organisations in terms of their deliverbilites, coding standard, financials and many other benefits.

I hope you have got a clear picture of what is CI/CD and why it is so important in today’s world. So, We are going to use Jenkins to automate our CI/CD. There are several other tools in the market like Bamboo, CircleCI, GitLab etc which can also automate your CI/CD Process.

Before automating Jenkins below softwares needs to be installed in your Local→

1>Install your Java JDK and set the environment variable properly.

2>Install ANT software from the internet and set its path variable.

3>Install Force.com ANT migration tool

You can write to me if you face any challenges while installing any of the above tools. I can write a complete blog for installing all the above tools and configuring it.

I understand you know how to check your java installation. To check your ANT installation, open your Command prompt and type ant -version. If you see below screen then your ant has been installed properly.

Your Force.com Ant Migration comes as a zip folder. After unzipping, you will see the folder structure below.

Copy your ant-salesforce jar file from the above image and paste it somewhere.

Now let’s open the folder that we have used in our previous Blogs “SFDCDEMOREPOSITORY” in our VS CODE.

Lets create a “lib” folder in our SFDCDEMOREPOSITORY and Match if your Folder looks like below

Open lib folder and Paste the ant-salesforce jar file that we coiped earlier. Go again to your Force.com Ant Folder and Open sample folder and Copy Build.xml and Build.property Files(Please refer to above folder image) and Paste it in your Current VSCode Directory. Final VS CODE should look like below.

Open your build.xml and Replace it with below script. Those who has worked previously on ANT tool Might understand this script. But in case you are new to ANT and does not understand this script. Nothing to worry about, this script basically tells my system which folder needs to be picked up for deployment. If you want to understand it in detail please let me know i will write another blog on ANT.

<project name=”Sample usage of Salesforce Ant tasks” default=”test” basedir=”.” xmlns:sf=”antlib:com.salesforce”>

<property file=”build.properties”/>

<property environment=”env”/>

<! — Deploy the unpackaged set of metadata retrieved with retrieveUnpackaged and run tests in this organization’s namespace only →

<target name=”deployall”>

<sf:deploy username=”${sf.username}” password=”${sf.password}” serverurl=”${sf.serverurl}” testlevel=”NoTestRun” logtype=”Detail” deployRoot=”force-app”/>

</target>

</project>

Now open your Build.Properties file and enter your salesforce destination username and password along with security token.

As part of the next step we are going to create a package.xml File which is very similar to our package.xml in the Manifest Folder. You can copy and paste the same file inside the force-app folder. As this is the folder that will be used for your deployment.

As this folder is already git initialized and so you will see these 4 new components are ready to be pushed to your remote repository.

You need tol push these changes to your GIT HUB repository. Once everything will be pushed to the git hub your repository looks like below

You can see all the new files and folders that we have added in our Local VS is now a part of our git Repository.

Lets go ahead and install jenkins→ follow this link to install jenkins in your machine

https://www.jenkins.io/download/

Make sure you are downloading the Long term Support version. It is more stable and very less prone to errors. You can execute the executable file and keep on following the instructions. You will see your jenkins is downloaded and asked for suggested plugins to install. I will suggest installing all the plugins. Once set, you need to setup your user. Refer to the screenshot below

You can run your Jenkins on Localhost:8080/. It is by default port and you can change it if you want.

Now your jenkins is set and ready to work, You will see the home screen of jenkins as below-

Lets start our build → Go to New Item →name your Project → select free style project →Click OK

Now we need to connect your Jenkins to your GIT HUB Repository. You will see below screen and enter the repository URL and Credentials.

Scroll down and go to Build trigger Section and select POLL SCM (you can select other options as well as per your need) and put the cron expression that says your jenkins will run every minute and pull the changes from your git repository.

Go to Build section and Select Invoke ANT

Once you will select invoke ANT, you will see Target box →Enter “deployAll” as per screenshot below and enter save.

Now your setup is Completed, you can go ahead and see how your build is going to RUN.

As you can see your build is running automatically in the Build History Section(remember you set your cron expression for every one minute). If your build doesn’t run you can click Build Now

You can click on the build and see the progress of the Builds

In my case My Build is Success and i can go to Console Output to check if everything has deployed Properly.

Refer to the Console output Screen below. As you can see below, my deploy has been completed and all the components has been deployed to my Destination Org

. You can see my Deployment Status from my org in the below Screen below

Your Whole CI/CD implementation is completed now. Your Developers will Push the code to the GIT and the Jenkins job will catch those changes automatically and send it to other environments for further testing or deployment.

That’s all you just automated your Complete CI/CD Process.

Please reach out to me if you have any doubts or questions while setting up your own CI/CD Process.

Thanks!