0

I am using ANT version 1.9.7 and Force.com Migration Tools version 37.0. Using the below script I get the error "failed to create task or type installPackage". I have not found documentation around this ANT task. According to this blog https://andyinthecloud.com/2013/06/23/look-ma-no-hands-automating-install-and-uninstall-of-packages/ you can use it in the build.xml file. Could I be using an unsupported task or perhaps I have done it incorrectly? I have not been able to identify documentation making this more clear. Any help is appreciated.

<project name="Test Package Creation" default="test" basedir="." xmlns:sf="antlib:com.salesforce">

    <property file="build.properties"/>
    <property environment="env"/>

    <!-- Setting default value for username, password and session id properties to empty string 
         so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
         will be treated literally.
    -->
    <condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
    <condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
    <condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

    <taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
        <classpath>
            <pathelement location="../ant-salesforce.jar" />            
        </classpath>
    </taskdef>


    <target name="deploypkg">
        <installPackage version="1.0" namespace="ns" username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" />
    </target> 
</project>

2 Answers 2

2

You have to use the "antlib:com.salesforce" namespace. Since you defined the namespace as "sf" (xmlns:sf means "define an XML namespace called "sf" with a location of "antlib:com.salesforce"), your "tasks" are defined in this namespace:

<sf:installPackage ... />

Alternatively, you need to make sure you start exactly as specified in the blog that you linked: you have to "import" the tasks into the default namespace to use them as demonstrated in the example file.


Edit: As it so happens, I think this is actually an outdated task; I don't see it in the v36 sources.

It looks like you should use the standard sf:deploy method:

<target name="...">
    <sf:deploy ... />
</target>

Using a package.xml file with the appropriate attributes:

<?xml version="1.0" encoding="UTF-8"?>
  <Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
      <members>*</members>
       <name>InstalledPackage</name>
     </types>
    <version>28.0</version>
  </Package>

Which you then specify the appropriate XML in the installedPackages folder:

<?xml version="1.0" encoding="UTF-8"?>
  <InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata">
  <versionNumber>1.0</versionNumber>
  <password>optional_password</password>
</InstalledPackage>

You can read all about it at Installing Managed Packages.

If you're not sure exactly how the format should be, try running a sf:retrieve with the package.xml file demonstrated here to get the files out from an org that have at least one installed managed package.

1
  • I suspected that installPackage may of been outdated. I even tried to use sf:InstallPackage as you suggested to no avail. "sf:deploy" appears to be the solution. Now if I could just automate creation of managed packages :)
    – Ian G
    Aug 13, 2016 at 15:30
0

Check out the below link to create a task in ant script : http://ant.apache.org/manual/tutorial-writing-tasks.html. I hope it will help you to figure out your problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .