Skip to content

April 15, 2013

CQ Workflow Tutorial: Export Workflow Models Quickly

by Andreas Schaefer

Update (5/17/2013):

There is a bug in the script when there are more than 10 files. This part will fix it:

# Do not change any of these
for f in $FILES
    echo File Name: $f
    NTEMP=`echo ${FILE##*-}|cut -d . -f1`
    echo NTEMP: $NTEMP
    if [ "$NTEMP" -gt "$INDEX" ];

So far I did not discuss how to manage the project even though if you look at the final project files I posted at the end of the Post you will see that it contains the Workflow Models as well.
In General I always keep the Workflow Models in my VCS (often my personal GIT as well as the Client’s VCS) just to make sure I have a track record of all the changes and can see how it evolves over time but also to have a way to easily undo a problematic current version. Because Workflow Models can only be edited inside the CQ Workflow Model Editor we need to find a way to export them quickly, easily and fast otherwise we might loose changes. That said I never to export the workflows directly into the VCS but rather export them into a temporary folder and then use a DIFF tool like Delta Walker for the Mac to move them over even if I just copy them without ever merging.


We need to do some setup work in order to make sure we can export the Package with a Script. The only thing we need to do is to create a Package inside the Package Manager (/crx/packmgr) with this pattern:

  • Name: {Group Name}-workflow-export
  • Version: 1.0
  • Group: {Group Name}

Then we need to edit the Package to add a Package Filter. You can add as many as you like but for me the only thing I need for now is the path to the Workflow Model which is either /etc/workflow/models or a Child Resource of it. Build the Package just to make sure it contain everything you want.


The script uses the RESTful API to the Package Manager which is not very difficult to understand. The bigger problem is to create a Unix script that is making sure I can keep a history of my downloaded packages. So this script will do that:


# This script will create a new build of the given package
# and download it to the given Directory with the next
# next number not taken. Then it will extract it into that
# folder with the same name.

# ATTENTION: This script has a few conditions:
# 1. Package with the Given Name must already exist in the
#    Package Manager ($
# 2. Package in part of the given Group
# 3. The Given Target Directory only contains files with
#    the given Pattern ($PACKAGE_NAME-<integer>.zip)
# 4. CQ Host, Port, Admin Username and Password are correct

# First variable here is the Group Name which is used to prefix
# the Package, the Target Directory etc. To make it easier
# to use this is the first parameter. Create another script
# per project.
# Second Variable is the Port Number
# Name of the Package without the Version

# Directory where the generated ZIP file will be placed in
# If it does not exist it will be created
echo Create Dir: $TARGET_DIR
mkdir -p $TARGET_DIR

# Name of the CQ Server
# Port of the CQ Server
# CQ Administrator User Name
# CQ Administrator Password

# Do not change any of these
for f in $FILES
    echo File Name: $f
    NTEMP=`echo ${FILE##*-}|cut -d . -f1`
    echo NTEMP: $NTEMP

# If it does not list any files then it will
# set index to '*' so we set it to the default
# of 0
if [ "$INDEX" = '*' ]; then
# Take next index number
echo Final Index: $INDEX

echo $FILE

# Build the Package through the Package Manager
echo Build the Package: $PACK_PATH
curl -X POST 

# Download the Package into our file
echo Download Package: $PACK_PATH to file $FILE
curl -u $USER:$PWD 
    http://$HOST:$PORT$PACK_PATH > "$FILE"

# Unzip the Downloaded File into a folder of the same name
mkdir -p $FOLDER
echo Unzip File: $FILE into Folder: $FOLDER
unzip $FILE -d $FOLDER

You can use that script like this: tutorial 4502

This will create a folder called tutorial in your Home Folder’s Download Folder, build and download the package and extract it in a sub folder of the same folder. Each downloaded ZIP file and extracted folder has this pattern tutorial-workflow-export-{index}.

For my various projects I created another Unix Shell Script with the Name of the Project which will have the Parameters already set.


Yes, you could do that with FileVault but my experience is that it is not very reliable and so I stopped using at all. Also if you are editing your workflows in a package that includes other parts like UI components etc then you must be very carful to download any changes from the Workflow before you start a build otherwise you might overwrite your changes with the old Workflow Models you have in your project. That is why this script is so handy because it takes literally no time to execute.

Finally, you could use a cron job to backup the Workflows automatically in the background using that script.

— Andy

Read more from Adobe CQ

Leave a comment