February 4, 2013

Ant: Did you know that using arg 'value' instead of arg 'line' will have an impact?

We heavily use Ant scripts for Build automation and it came as a big surprise that using arg 'value' instead of arg 'line' will have an impact. This article will focus on the problem statement that had issues and the Solution for the same.

Problem Statement:

There were two issues as detailed below while creating the Tags the Ant Script.
 
1) When the SVN authentication credentials are saved

-->The below script is creating a directory with the time stamp but its including the username and password also in the directory name (e.g  "20130130_044807 --username testuser --password testpass")
-->We tried with many options but it's still taking the username and password in the directory name.
--> Tagging is working properly.
<?xml version="1.0"?>
<project name="samplescript" default="TagSource">
<property name="SVN_UNAME" value="testuser"/>
<property name="SVN_PWD" value="testpass"/>
<property name="SVN_LOGIN" value="--username ${SVN_UNAME} --password ${SVN_PWD}"/>
<property name="SVN_TAG_MSSG" value="tagging"/>
<tstamp>
                <format property="TODAY" pattern="yyyyMMdd"/>
 </tstamp>                        
                   <tstamp>
                      <format property="NOW" pattern="HHmmss"/>
  </tstamp>  
 <property name="svn_dir" value="${TODAY}_${NOW}"/>
 <echo> ${svn_dir} </echo>
 <property name="SVN_URL" value="http://url/trunk/${svn_dir}"/
 <echo> ${SVN_URL} </echo>
<target name="TagSource" description="Creating a directory and tagging the working copy" >
   <exec executable="svn">
                <arg value="mkdir"/>
                <arg value="${SVN_URL} --username ${SVN_UNAME} --password ${SVN_PWD} " />
                <arg value="-m Creating_dir" />
   </exec>               
   <exec executable="svn">
                <arg value="copy"/>
                <arg value="D:\backup\SQL\xsl" />
                <arg value="${SVN_URL} --username ${SVN_UNAME} --password ${SVN_PWD} " />
                <arg value="-m tagging" />
   </exec>
</target
</project>
2) When the SVN authentication credentials are not saved:
-->The same above script is failing with the below error:
           TagSource:
     [exec] Authentication realm: <http://url:80> Subversion Repo 
The main issue here is It's not considering the username and password provided in the script.
 
Solution:
Instead of the following statement,
< arg value="${SVN_URL} --username ${SVN_UNAME} --password ${SVN_PWD} " />

use

< arg line="${SVN_URL} --username ${SVN_UNAME} --password ${SVN_PWD} " />

arg value treats entire value as single command separated by space.
arg line will consider this as separate command delimited by space.

Thanks to Mayur Bhatt for the solution.

No comments:

Post a Comment