13

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?

1
  • did any of these answer below help you out?
    – Phil B
    May 14 '15 at 16:02
8

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>
1
  • Is it possible to omit version in installPackage call? I mean, if I want to install the latest available package version (and don't know exact number), can we use something like version="*" or some other special keywords are supported, maybe?
    – wesaw
    Jul 24 '17 at 19:34
2

The Package object in the Metadata API allows you to create or update packages, so presumably this would be the experience you would want to use for automation. I'm not aware of an out-of-the-box solution, but it would be trivial to make a shell script to invoke the Metadata Toolkit and commit. That script might look like this (Linux):

ant deployChanges
result = $?
if [ "$result" -eq 0 ]
then
    git commit
fi

It would be similar in Windows/DOS:

ant deployChanges
if ERRRORLEVEL == 0 GOTO commit
GOTO end
commit:
git commit
end:

(NOTE: I'm not very strong on shell scripting any more, so either example may require tweaking.)

Alternatively, you could also write a Perl script that could build a dynamic package.xml, then invoke the commit and deploy commands in the order of your choice.

1
1

The SFDC Foundation Published this overview of how they are doing it - should have some useful pointers

0

You can use the Metadata API to retrieve, deploy, create, update or delete customization information, such as custom object definitions and page layouts, for your organization. This API is intended for managing customizations and for building tools that can manage the metadata model, not the data itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.