Automatic package creation in Salesforce

I’m developing a managed package in Salesforce and I’d like to have continuous integration system to produce packages automatically and test it. I have everything stored in Git: classes, pages and metadata, unit tests and functional tests (I use Selenium). It’s clear how to upload your stuff to target org (use migration tool), but how to add/remove stuff to/from package and create it automatically. Is there API or third party tool to do it?
For example, I have my managed package in target organization and I make a commit which adds one class and change one page. I can easily upload this commit to target organization, but how to add a new class to my package and change existing page automatically.
I believe all people who develops managed packages in Salesforce should encounter the same problem. Any ideas?

Answer

Package Update Automation

When you deploy to your packaging org, specify the autoUpdatePackage setting. Then if you wish use the retrieve to download and commit the new package.xml back into your Git repository. Though personally i consider this step optional, since the package.xml in the packaging org is typically not the one you want to manage in your Git org for day to day deployments (e.g. use of wildcards etc).

autoUpdatePackage. Optional. Defaults to false. Specifies whether a deploy should continue even if files present in the zip file are not specified in package.xml. Do not use this parameter for deployment to production organizations.

Here is an example from one of our Ant scripts…

<target name="packaging.deploy">
    <sf:deploy
        username="${sf.username}" password="${sf.password}" autoUpdatePackage="true"
        deployroot="${basedir}/../source/ir/src" singlePackage="true" maxPoll="500" runAllTests="true" logtype="Debugonly"/>    
</target>

Package Upload Automation

In respect to automating the upload, there is no API for this, though i have heard of people have success using Selenium for this, via the Java WebDriver it provides as part of the Ant build script.

Package Installation Automation

The metadata API does permit the automated install of packages now. You can implement this by deploying the .installedPackage component. I’ve written some help Ant targets to make this process easier, you can read more here. This is an example shown in the blog.

<project name="installdemo" default="build" basedir=".">
    <!-- Load standard properties -->
    <property file="${basedir}/build.properties"/>    
    <!-- Import macros around sf:deploy to install/uninstall packages -->
    <import file="${basedir}/lib/ant-salesforce.xml"/>
    <!-- Default target -->  
    <target name="build">     
        <!-- Install the package with namespace packagea -->
        <installPackage namespace="packagea" version="1.0" packagePassword="fred1234"
           username="${sf.username}" password="${sf.password}"/>
        <!-- Uninstall the package with namespace pacakgea -->
        <uninstallPackage namespace="packagea"
           username="${sf.username}" password="${sf.password}"/>     
    </target> 
</project>

Attribution
Source : Link , Question Author : Mike Raven , Answer Author : Andrew Fawcett

Leave a Comment