Skip to main content

Automated Salesforce Deployment Using Jenkins


Salesforce deployment is a painful manual task. You need to configure many things every time you do deployment in salesforce irrespective of what method you are using for deployment.

This article is to setup automated salesforce deployment, using open source software Jenkins

Features:

  •   You just need to configure everything one time for automated deployment.
  •   You can receive email after every deployment.
  •   You can schedule time and date according to your requirement.

Limitation:

  •   You just need to keep your Laptop in sleep or turn on to start deployment at specific time. 

Prerequisite Software:

  •  ANT
  •  GIT
  •  PuTTYgen


Jenkins Setup:

here are two ways to start with Jenkins,
  1.   Install Jenkins in local system.
  2.   Use cloudbees Online.
In this article I will use Jenkins installed on my local system. You can refer below link to install Jenkins. Install for Windows.   



Jenkins Setup - Start/Stop/restart Jenkins server:

For first time, Open Command prompt in administrative mode and go to the path where Jenkins folder is created (e.g : C:\Program Files (x86)\Jenkins), and run below command
  •    java -jar jenkins.war

Then open server in browser (e.g : https://localhost:8080)

Follow the instructions and install all recommended plugins. After installation make sure below plugins are installed in your Jenkins server, if any plugin is missing you need to install that.

You can verify all installed plugin at ‘Jenkins/manage plugin’ (http://localhost:8080/manage)

  1. Folders plugin
  2. build timeout plugin
  3. credentials binding plugin
  4. timestamper
  5. workspace cleanup plugin
  6. ant plugin
  7. pipeline
  8. github branch source plugin
  9. pipeline: stage view plugin
  10. bitbucket plugin
  11. git plugin
  12. email extension plugin
  13. mailer plugin

If you want to start , stop or restart Jenkins after first login,Open command prompt in administrative mode and Go to the path where Jenkins is installed (e.g: C:\Program Files (x86)\Jenkins). Run below appropriate command.

  •   Jenkins.exe start
  •   jenkins.exe stop
  •   jenkins.exe restart
Note : To start with configuration for automated deployment, you need to setup repository for your code development, I am using Bitbucket. 

Automated Deployment Setup :


Generate SSH key using Puttygen : 

  1. Generate SSH key and Save you private key locally.
  2. Setup SSH Key in Bitbucket account :
    • Go to Account settings and Add generated SSH public key in ‘SSH Keys’ tab.

Setup Jenkins project for automated deployment:

  1.  Create new ‘Free style’ project using ‘New Item’ link.
  2.  Then Enter Project Description and check ‘GitHub Project’ checkbox and provide ssh URL of your bitbucket project repository that you want to integrate for automated deployment. It will look like this – ‘git clone git@bitbucket.org:Shivani_personal/project-practice.git

  3.  From ‘Source Code Managemant’ tab select ‘Git’ and enter same ‘SSH URL’ as above.
    • In ‘Credentials’ picklist, select ‘ADD’ and enter below details.
      • Domain – Global Credentials
      • Kind – SSH Username with private key
      • Scope – Global
      • Username – Enter you bitbucket login username
      •  Private key – Select ‘Enter Directly’ and enter your Private key that you saved in your local machine while generating the key.
      • Description – Give description of you key to remember
      • And click on ‘Add’ button
      • Select newly created credentials in ‘Credentials’ Picklist.

    •  Branches to Build – Add Branches for which you want to trigger automated deployment. E.g – for master branch write (*/master)
  4.   From Build Trigger tab select appopriate option to trigger build, Some useful options are below.
    • Build periodically – You can specify when you want to trigger build using CRON expression. Refer below link for creating CRON expression
    • Build when change is pushed to bitbucket – It will start build when you commit anything in branch that you specified in above steps.
    • Poll SCM – we need to specify CRON expression here, it will check if there is any new commits in branch after the specified time mentioned in CRON expression, and trigger deployment for that new commit.
  5.   From ‘Build Environment’ tab select below options.
    • Delete workspace before build starts.
    • Abort the build if build stucks.
      • Time-Out Strategy – Likely Stuck
      • Time Out actions – fail the build
    • Add Time stamp to console output (optional)  - if you want to see the time of build in console select this option.

  6.   From ‘Build’ tab select below options.
    • Select ‘Invoke Ant’
    • Targets – Select Target that you will specify in ‘Build.xml’ file in below step.
    • Build file – enter ‘C:\Program Files (x86)\Jenkins\’ and add your ‘build.xml’ and ‘build.properties’ at mentioned path.

Comments

Popular posts from this blog

Salesforce lightning component e.force:navigateToURL

This article will explain how to use ‘e.force:navigateToURL’ lightning component to navigate the system to any URL (visualforce page, record, any custom URL). Syntax of ‘e.force:navigateToURL’ var urlEvent = $A.get("e.force:navigateToURL");         urlEvent.setParams({           "url": "/" + recordId ,             "isredirect": "true"         });         urlEvent.fire(); Description of the parameters, 1.        URl – Set this parameter to the required URL that you want to redirect, in this example ‘recordId’ is my variable with has the Id of the record I want to redirect. We can use static URL (e.g https://www.salesforce.com ) as well. 2.        Isredirect – This is optional, this flag will not...

Best practices for Data Loading in Salesforce

Data loading is a very common requirement in most of the salesforce projects. We need to load many master data and transactional data in production based on requirements that include thousands of records. In this article, I am going to list some best practices that we can follow and keep in mind while loading data in production. 1.     Organization-Wide Sharing defaults - While loading data in production, if objects have ‘Private’ OWD then it does additional processing in the background. Therefore, it is better to load data using read/write OWD and change it to ‘private’ after cutover. 2.     Workflow rules, validation rules, and triggers - If these tools are enabled in your production org while loading data, it can give many errors and it may slow down the process. Therefore, it is recommended to disable these tools before loading data.   3.     Bulk API Vs. SOAP API - SOAP API is useful for small data sets where...

How to start with salesforce

'Salesforce' is cloud computing company, which provides many services and uses many technology to deliver services. Salesforce is high demanding cloud computing technology that provides 'PAAS' to create your application on cloud and deliver to users.  But how to start with salesforce. This article will provide you basic idea to start with Salesforce if you are new to this technology.  If you are a developer, it will be very easy to jump in Salesforce technology and master it. How Salesforce is useful to deliver solution: Salesforce platform will help you to deliver CRM Applications. You can build CRM applications which can be used by businesses to track sales activity. Salesforce Platform is employed across all industries to build and launch game changing apps for every department in a company, including HR, IT, operations, finance, legal, and marketing.  Here is the example of some applications that you can build with help of salesforce. ...