Using sshexec from ANT in Eclipse for build files

Following on from other p[osts, we continue to improve our build files for deployment of client sites. Our latest addition is the sshexec task for clients using Linux or a LAMP environment to host their site.

Our build files move the code out of SVN, zip it up, commit the build record back to SVN, and FTP the resulting file to the site. With ssh we can now unzip the file and have ANT do all the work for us.

sshexec is not one of the core tasks in ANT, you can find out about ANT dependacies here. Currently you need jsch.jar 0.1.29 or later from the JCraft Java Secure Channel project.

Place the JAR file into [eclipseroot]\plugins\org.apache.ant_1.7.0.v200803061910\lib directory

Once you have placed your jar file, you need to get Eclipse to load them at runtime. I read somewhere that using the ANT folder above and a simple restart would have Eclipse pick them up, but that didn't work for me.

1. Open Eclipse 2. Window > Preferences 3. Ant > Runtime 4. Ant Home Entries (Default) 5. Click Add External JARs 6. Navigate to [eclipseroot]\plugins\org.apache.ant_1.7.0.v200803061910\lib or wherever you unzipped the jar files 7. Select the jsch.jar file 8. Open > Apply > OK 9. Restart Eclipse

You should now be able to use the following target to make it happen, this example unzips a predefined zip file:

<target name="SSHunzip">
      
   <echo message="Unzipping Zip file" />
   
   <sshexec host="${projectURL}"
      username="${SSH.Username}"
      password="${SSH.Password}"
      trust="true"
      command="unzip -o ${FTP.Development.RemoteLocation}/${projectName}.${build.number}.${svn.info.rev}.zip -d ${FTP.Development.RemoteLocation}"/>

</target>

Calling ANT scripts from ColdFusion

We have been fiddling with getting CF to call a self updating ANT script. There are a few articles around about the undocumented cfant tag.

Getting cfant to run a build file is not all that hard, we loop over the sites in our dev server directory, check to see if a build file exists and try and run the 'updateserver' target.

<cfset buildFile = 'e:\sites\' & SiteName & '\httpdocs\build\build.xml'>
<cfant buildFile="#buildFile#"
defaultDirectory=""
anthome="C:\Program Files\apache-ant-1.7.1\"
messages="output"
target="updateserver"/>

A couple of things to note:

There seems to be a memory leak in here. This runs happily every half an hour for about 3 hours, then jrun decides not to go any more. There is no way we can find to pass in user variables to ANT. i.e. you cant pass in a username / password as you would through the console in Eclipse or via the command line. This is a bit of a down side. We hoped we could have one generic build file and pass the path to it rather than having a build file in each directory.

More on this self updating script shortly.

ANT SVN update project script

We now have a solution to update each of our customer sites on our devserver. We installed ANT on the server to the default directories and then called the undocumented cfant tag via ColdFusion.

Installing the necessary files to get the SVN task working isnt hard, you simply download and drop these files into the /lib directory under ANT home. In our case thats C:\Program Files\apache-ant-1.7.1\lib

svnant.jar svnjavahl.jar svnClientAdapter.jar svnkit.jar ganymed.jar

You can lay your hands on all these files at SVNAnt

[More]

Using the Ant FTP Task in Eclipse

And here is another joy of ANT - you can move files by FTP. Its not one of the core tasks in ANT, so you can be forgiven for trying it, and it not working. Go check out the ANT Manual FTP Task page and it tells you the components you require.

[More]

Using the ANT build.number file

I was wondering how to keep track of how many builds have taken place, putting it together into a overall product version number with the Subversion Revision number.

It turns out that ANT actually keeps a record of builds itself using the Buildnumber task, all you have to do is produce a blank build.number file. If the build.number file is local to the build.xml you need no special attributes, ANT will update the build number for you.

<target name="buildnumber">
      
   <buildnumber/>
   <echo message="ANT Build number ${build.number}" />
      
</target>

How good is that? Marvellous I think is the word you need.

Keeping the private stuff out of ANT config files

I have been using ANT to get builds done of the many projects we work on, and one of the things that has bugged me was that the SVN username and passowrd was stored in the build.properties file.

Today the ANT Manual came to the rescue with the input task.

[More]

How to get the SVN revision number for use in ANT

As part of my build and deploy process I wanted to get the revision number of the working copy and append it into the application so its visible.

To do this you need to have already installed the SVNAnt task, (see my previous post) as its not a core ANT task.

[More]

Exporting a SVN Working Copy with ANT

Once you have installed the SVN task to Eclipse, you can begin to look at the possibilities. For example in a deployment scenario you could use ANT to export the HEAD revision so you have a clean set of files ready for moving by FTP or some other means.

There certainly isnt any VooDoo here, its all very straight forward.

<!-- export current head revision -->

<echo message="exporting to ${buildDir}" />

<property name="buildDir" value="c:/export/${projectName}" />

<svn username="username" password="password">
   
   <export srcUrl="http://localhost/svn/testrepository" destPath="${buildDir}" revision="HEAD" />

</svn>

Installing SVNAnt into Eclipse

On my road of exploration for ANT, and the end goal of using it for deployment, I have had to tackle how to get files out of SVN ready for moving to a server. This means getting ANT to run the equivalent of an svn export from the command line.

This is possible using the command line client through ANT thus:

<exec executable="svn">
<arg line="co ${svn.projecturl} ${build.temp} -r ${svn.revision} --username ${svn.username} --password ${svn.password}"/>
</exec>

However there is a nicer way that doesn't involve installing the SVN command line client. Enter SvnAnt.

[More]

Using ANT from Eclipse

I have recently taken the plunge into ANT for use in deployment and doing some mundane tasks, and since I use Eclipse I have been playing with the integrated version that comes bundled.

There were a few things that are not very well documented (or I could not find) that took me a while to figure out, so I though I would share.

[More]

BlogCFC was created by Raymond Camden. This blog is running version 5.9.001.