Ant target to deploy an ear file in Tibco Administrator
Facts - Tibco
Monday, 19 December 2011 20:52

This note has been tested with Tibco Runtime Agent (TRA) 5.6, Tibco Administrator 5.6, Ant 1.8 and Groovy 1.8

Deploying of (BusinessWorks) ear files in Administrator is often easier using a script calling AppManage (in the TRA distribution) than doing it manually in the Administrator web frontend. With scripted deployments the ear file and the deployment xml file containing the process and global variable settings is usually extracted from a version control system. So a working scripted deployment guarantees that these settings will not be lost. In addition a scripted deployment can be even easier executed via a web frontend or built system such as Jenkins.

The following ant target deploys an ear file using AppManage:

<project name="deployEar" xmlns:fl="antlib:it.haefelinger.flaka">
  <fl:properties>
    <!-- leading spaces are stripped from properties -->
    appmanage.nostart = #{${tibco.app.dontstart}==true ? "-nostart" : ''}
    appmanage.nostop = #{${tibco.app.dontstop}==true ? "-nostop" : ''}
    appmanage.forceDeployment = #{${tibco.app.forceDeployment}==true ? "-force" : ''}
  </fl:properties>
 
  <target name="deployEar" depends="...">
    <scp trust="true" file="${tibco.app.earfile}.ear" todir="${ssh.user}:${ssh.password}@${tibco.admin.host}:~"/>
    <scp trust="true" file="${tibco.app.config}.xml" todir="${ssh.user}:${ssh.password}@${tibco.admin.host}:~"/>
 
    <sshexec trust="true" host="${tibco.admin.host}" username="${ssh.user}" password="${ssh.password}" 
    command="cd ${serverTibcoTraDir}/5.6/bin; 
./AppManage -deploy -app ${tibco.admin.dir}/${tibco.app.name} -domain ${tibco.admin.domain}
-deployconfig ~/${tibco.app.config}.xml -ear ~/${tibco.app.earfile}.ear 
-user ${tibco.admin.user} -pw ${tibco.admin.password}
-desc '${appmanage.deployment.description}' 
${appmanage.nostart} ${appmanage.nostop} ${appmanage.forceDeployment};
tail -n 30 ${serverTibcoTraDir}/domain/${tibco.admin.domain}/logs/ApplicationManagement.log > ~/AMlast30Lines.log" 
failonerror="false"/>
 
    <scp trust="true" file="${ssh.user}:${ssh.password}@${tibco.admin.host}:~/AMLast30Lines.log" todir="."/> 
  </target>

Note the use of Flaka to manipulate ant properties.

Note also several ant properties. These can be supplied from the command line or from Jenkins/Hudson:

  • Server credentials: tibco.admin.host, ssh.user and ssh.password.
  • Tibco Administrator credentials: tibco.admin.domain, tibco.admin.user
  • Appmanage location and Administrator domain: ${serverTibcoTraDir}/5.6/bin, ${tibco.admin.domain}
  • Ear file and global variables: ${tibco.app.earfile}.ear, ${tibco.app.config}.xml.
  • Name and directory of the deployment in Administrator: tibco.admin.dir and tibco.app.name.
  • Deployment description, overwrites the description in the global variables xml: appmanage.deployment.description
  • Other parameters for AppManage, boolean values: appmanage.nostart, appmanage.nostop, appmanage.forceDeployment

If you leave out the description in the AppManage command line then AppManage uses the description in description tag in the configuration xml. You could manipulate the description in AppManage to combine information from the version control system and the configuration xml. When using subversion you could add the following code:

<target name="setDeploymentDescription">
  <groovy>
    def application = 
        new XmlSlurper().parse(new File(properties.'basedir' +'/' +properties.get('tibco.app.config') +'.xml'))
    properties.'appmanage.deployment.description' = 
      application.description.toString() +
      ', svn revision=' +properties.'svnRevision' +
      ', svn url=' +properties.'svnRootUrl' +'/' +properties.'svn.package.release.path'
  </groovy>
</target>

Note the call to the toString() method. This call does the conversion from an XML node to a string. Without this conversion the string concatenation fails.