Pushing component versions into UrbanCode Deploy

man-push-mdUrbanCode Deploy has numerous source config types that it can connect to as a source for new component versions.  And most of those types have an option that allows you to automatically retrieve new versions when they appear.

source config[ Note:  As of version 6.0, this option is available for every source config type. However, there is at least one type that does not poll for new versions even though you check the checkbox.  Check the logs to make sure that you are seeing polling.  By the way, Freddy’s latest blog post discusses the use of plugins for source config types which gives you more control over this.]

check periodThere is also a System Setting that allows you to configure the polling interval.

If you extrapolate out to hundreds if not thousands of components, you can quickly see that there will be an awful lot of polling going on.  For some source config types this may be a burden and cause a noticeable degradation in performance.  That is why pushing content into UrbanCode Deploy is recommended.

So how is that done?   In this post we will talk about inserting steps into an Ant script to push new content into UrbanCode Deploy using command line methods.   Here are some considerations that go with the example below.

  1. You must have the UrbanCode Deploy command-line utility installed on the build server.
  2. Many of the UrbanCode Deploy command-line commands return a JSON file.  If you wish to retrieve information from the returned JSON file, you must parse the JSON.  Rhino is an open source javascript implementation that can be used to accomplish this.  If you chose to use this solution, you must include the Rhino javascript implementation jar file in your Ant execution path.  You do this by adding a -lib parameter to the Ant execution specifying the Rhino jar file to include in the Ant classpath.example:   -lib /opt/rhino/js-1.7R4.jar

    This jar file must be installed on the build server, or you could include it as part of your build project and reference it from there.

<!-- create new version for jke.db component -->
<exec executable="/bin/bash" outputproperty="jke.db.component.output">
      <arg value="/opt/udclient/udclient"/>
      <arg value="-weburl"/>
      <arg value="${udclient.weburl}"/> <arg value="-username"/>
      <arg value="${udclient.username}"/>
      <arg value="-password"/>
      <arg value="${udclient.password}"/>
      <arg value="${udclient.verbose}"/>
      <arg value="createVersion"/>
      <arg value="-component"/>
      <arg value="jke.db"/>
      <arg value="-name"/>
      <arg value="${buildTimestamp}"/>
</exec>

<!-- Rhino - an open source impl of JavaScript to parse JSON. -->
      <script language="javascript">
      <![CDATA[ 
            json = project.getProperty("jke.db.component.output");
            echo = project.createTask("echo");
            echo.setMessage("Parsing Response:");
            echo.perform();
            echo = project.createTask("echo");
            echo.setMessage(json);
            echo.perform();
            // Parse JSON response
            obj = JSON.parse(json);
            // retrieve the new component version id
            id = obj.id;
            echo = project.createTask("echo");
            echo.setMessage("jke.db.component.id=" + id);
            echo.perform();
            // set project property to be used later             
            project.setProperty("jke.db.component.id", id);
      ]]>
</script><!-- add files to new version of jke.db component -->
<exec executable="/bin/bash">
      <arg value="/opt/udclient/udclient"/>
      <arg value="-weburl"/>
      <arg value="${udclient.weburl}"/>
      <arg value="-username"/>
      <arg value="${udclient.username}"/>
      <arg value="-password"/>
      <arg value="${udclient.password}"/>
      <arg value="${udclient.verbose}"/>
      <arg value="addVersionFiles"/>
      <arg value="-component"/>
      <arg value="jke.db"/>
      <arg value="-version"/>
      <arg value="${buildTimestamp}"/>
      <arg value="-base"/>
      <arg value="${destdir.db}"/>
</exec>
  1. The /bin/bash executable sections are running UrbanCode Deploy command-line commands (createVersion and addVersionFiles).
  2. The UUID of the newly created version is grabbed and put into a variable by the Rhino javascript code.  (It is not used in this example but included for reference).
  3. Various variables are used in the arguments that are either defined in the Ant script itself or passed into it when executed.

This could be easily rolled into reusable ant tasks and utilized throughout your Ant build scripts.  The benefit of this method is that you only push when a successful build occurs. However, this could also be a drawback as you may not want to push every build but only ones that pass some type of test.  If your testing is also included in your build process, you can push the new component into UrbanCode Deploy only if it passes those tests.

All in all, a push model for new component versions is the desired approach and you should look into making it a best practice for your organization.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s