Recipes by Category

App Distribution (2) Bundle logic, interface and services for distribution. App Logic (37) The Apex programming language, workflow and formulas for logic. Collaboration (6) The Salesforce Chatter collaboration platform. Database (29) Data persistence, reporting and analytics. Integration (33) Web Service APIs and toolkits for integration. Security (9) Platform, application and data security. Tools (4) Force.com tooling User Interface (36) Visualforce MVC and metadata-drive user interfaces. Web Sites (12) Public web sites and apps with optional user registration and login.
Beta Feedback
Cookbook Home » Ant Dump: Daily Source Snapshots

Ant Dump: Daily Source Snapshots

Post by Kyle Bowerman  (2012-01-23)

Status: Unverified
Level: intermediate

Problem

Sometimes you want to take a daily snapshot of you entire code base. This may be weekly, daily, or even several times during a day depending on the velocity of development. The optimal way to do this is check your code into a version control repository like GIT or SVN. For many of us, we just want a local "down and dirty" way to create a daily snapshot that does not overwrite the previous day.

Solution

With only adding a few lines to your Ant build.xml file you can run an Ant task that will dump your org's code into a newly created directory in the format OrgNickname-todaysDate.

1. The first Step is to edit your build.xml file and call the built-in property TStamp to initialize the value. For example, after the last property tag in your build.xml, add the following line:

<tstamp/>

2. Next, add an org nickname, which will be a prefix on all the directories that are created. For this example, I use QA, but you could use anything you like:

<property name="orgNickName" value='QA'/>

3. Combine the previous two values to get the directory name. For example, I used the variable <em>mydir</em> to store this, which I then call from the task named <em>dump</em>:

<property name="mydir" value='${orgNickName}-${DSTAMP}'/>

4. The final step is to add the <em>dump</em> task to the build xml file:

 <target name="dump">
            <echo> mydir = ${mydir}</echo>
        <mkdir dir="${mydir}"/>
        <sf:retrieve 
                username="${sf.username}" 
                password="${sf.password}" 
                serverurl="${sf.serverurl}" 
                retrieveTarget="${mydir}"  
                unpackaged="unpackaged-all.xml" 
                pollWaitMillis="10000" 
                maxPoll="20"/>
 </target>

As you can see, I print the newly created directory name to the screen just as a reference. This is a left over debug statement that I kept in to remind me what day it was.

5. And finally, run the command <strong><em>ant dump</em></strong>

I have never scheduled this from a cron job, but consider this if you want to automate this task.

Share

Recipe Activity - Please Log in to write a comment

I am having the same problem as Kory. What should be the content of the unpackaged-all.xml file?

Thanks.

by Jose Garcia  (2012-10-22)

I'm receiving an error when I attempt this: BUILD FAILED. Should provide a valid retrieve manifest 'unpackaged'.

It appears ANT is looking for the xml file calledĀ "unpackaged-all.xml" in the build.xml file. Since this does not exist in the ANT directory, it's throwing an error. Do I need to create a generalĀ "unpackaged-all.xml" file that would pull in all of the objects in the Salesforce org? If so, how would I go about creating such a file?

Thanks!

by Kory Howard  (2012-06-27)

Good one.. if you work indpendently, but if in a team then have to do it in SVN to get the latest updates !!

Cheers
JJ

by Jatin Jain  (2012-02-18)

X

Vote to Verify a Recipe

Verifying a recipe is a way to give feedback to others and broaden your own understanding of the capabilities on Force.com. When you verify a recipe, please make sure the code runs, and the functionality solves the articulated problem as expected.

Please make sure:
  • All the necessary pieces are mentioned
  • You have tested the recipe in practice
  • Have sent any suggestions for improvements to the author

Please Log in to verify a recipe

You have voted to verify this recipe.