Sunday, March 27, 2016

How to automate your salesforce deployment using Ant

Recently I was thinking to make automatic deployment mechanism to save time that was invested in weekly deployments. So after scratching the surface of Ant Migration Tool I cam up with this script to automatically extract and deployment class and trigger from one org to another.

Option 1-
Step 1. Must have JDK 1.6 or higher
Step 2. Install Ant to your machine use this "http://ant.apache.org".
Step 3. Download Salesforce Ant Migration ZTool Jar package.
Step 4. Create/Clone two folder using the sample folder in the zip.
Step 5. Provide Username password to both the Build.property files.
Step 6. Use this code and save it to Auto.bat in any location
ECHO Retrieve and Deployment auto script started..
cd\
cd <Path to>\Retrieve Meta
start /W ant retrieveUnpackaged ^&^& exit
Xcopy  /S /I /E /Y "<Path to>\Retrieve Meta\retrieveUnpackaged"  "<Path to>\Deploy Meta\codepkg"
ECHO Retrieve file copied to Deployment folder..
cd\
cd <Path to>\Deploy Meta
start /W ant deployCode ^&^& exit
ECHO Retrieve and Deployment auto script stoped..
PAUSE Press Enter to close

Where <Path to> is the path where you extracted the Ant Migration Tool and cloned folders.

Option 2-
Have a ant build.xml configured with two targets first for retrieve and second for deployment and link them inside another target like <target name="all" depends="retrieve, deploy">
</target> then open cmd and run this
ant -f build.xml all