Apache Ant – Extract a string from property using regular expression
The Ant-Contrib library is a must have tool if you need to have more control on your build flow. Here is another example on using the propertyRegex task provided by Ant-Contrib to select or replace a...
View ArticleApache Ant – Run piped command in exec task
The Ant <exec> task allows us to run shell command in Ant script. We could provide input arguments like the following example which prints today’s weekday. build.xml <?xml version="1.0"...
View ArticleAnt – Execute Grunt and fail it on error
I want to execute a Grunt build in an Ant build project. This could be done by using <exec>. <?xml version="1.0" encoding="UTF-8"?> <project name="Ant Called Grunt" default="grunt"...
View ArticleApache Ant – Get the SVN revision number by exec task
In Apache Ant, we can use the <exec> task to execute shell command in Ant script. Previously i have shown you how to integrate Apache Ant with SVN. Apache Ant and SVN Integration If you only...
View ArticleApache Ant and SVN Integration
We could setup a SVN client in Apache Ant. Here is an example. 1. Download the following .jar files @ the repository.pentaho.org svnant-1.3.0.jar svnClientAdapter-svnant-1.3.0.jar...
View ArticleApache Ant – Get the current running Ant version in Ant script
I am trying to figure out which Apache Ant version is running on the Jenkins server. Starting from Apache Ant 1.7.0, you can make use of the <Antversion> task to determine the running Ant...
View ArticleApache Ant – Missing environmental variables config in sshexec
The <sshexec> task is a very handle tool for executing command on the server through SSH. But i find that the SSH session does not have the proper environmental variables. Here is a simple...
View ArticleApache Ant – Check if a string property contains a certain string
The following example which check if a string property contains a another string. <project name="ant-string-contains-example" default="run" basedir="."> <target name="run"> <property...
View ArticleApache Ant – Iteration within a specific number range
Previously i have published a post about using for loop in Ant to read a text file line by line. Apache Ant – for loop example for reading a text file The <for> task requires a list attribute...
View ArticleApache Ant – Get and Set Ant property in Javascript when using the script task
In Ant script we could write Javascript code using the <script> task. In the following example, i will pass 2 Ant properties to Javascript and print the square value to the console. Also at the...
View ArticleApache Ant – Concatenate text files
This is an example showing how to concatenates files using Ant script. 1. Assume you have the following files in your Ant project folder. ant-for-example | - build.xml | - Text-1.txt | - Text-2.txt | -...
View ArticleApache Ant – Error/Exception Handling
The Ant-Contrib library also provides <trycatch> task for error/exception handling. Here is an example of build.xml which demonstrate the usage and again it requires the ant-contrib-1.0b3.jar...
View ArticleApache Ant – Capture Ant output log using recorder task
There is a <record> task in Ant so you could save the Ant output during the Ant Build. Here is an example. 1. build.xml <project name="ant-recorder-example" default="record" basedir=".">...
View ArticleApache Ant – for loop example for reading a text file
The Ant-Contrib library also provides u a <for> task to do iteration. Here is an simple Ant example which read a text files and print it to the Ant build output. 1. This is the structure of our...
View ArticleMaven – Run sshexec and scp in maven-antrun-plugin
If you want to use the <sshexec> or <scp> tasks in the maven-antrun-plugin, you may find the following error. [ERROR] Failed to execute goal...
View ArticleMaven – Run maven-antrun-plugin without attaching to a lifecycle phase
Long time ago, i had a post about running Ant in Maven using the maven-antrun-plugin but the Ant script would be attached to the Maven lifecycle phase. Maven – Using Ant tasks with maven-antrun-plugin...
View ArticleAnt – Stop the script without failing the build
We can use the <fail> Ant task to exit the Ant script but this will fail the build. Sometimes we may have some checking during the build such that it could exit peacefully without build failure...
View ArticleApache Ant – Check if a file exists with wildcard
The <available> command can help you to check if a file or folder exists. Unfortunately it doesn’t support wildcard checking. Here is an workaround using the <pathconvert> such that we can...
View ArticleApache Ant – Using scp and sshexec tasks in build.xml
Unlike the Ant Contrib library which could be included thru the <taskdef>, the <scp> and <sshexec> tasks could not be included in this way or it will throw the following errors. A...
View ArticleApache Ant – String to uppercase / lowercase using ScriptDef
In Apache Ant, we can define custom task using MacroDef. Apache Ant – Define your custom Ant Task using MacroDef Other than that, Apache Ant is now shipped with a Javascript engine so we could use...
View Article