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,
- Install Jenkins in local system.
- 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)
- Folders plugin
- build timeout plugin
- credentials binding plugin
- timestamper
- workspace cleanup plugin
- ant plugin
- pipeline
- github branch source plugin
- pipeline: stage view plugin
- bitbucket plugin
- git plugin
- email extension plugin
- 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 :
- Generate SSH key and Save you private key locally.
- 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:
- Create new ‘Free style’ project using ‘New Item’ link.
- 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’
- 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)
- 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.
- 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.
- 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
Post a Comment