I have defined a macro in ANT that checks if a dir exists on a remote linux box:
<macrodef name="checkIfDirExists">
<attribute name="host" />
<attribute name="username" />
<attribute name="password" />
<attribute name="dir" />
<sequential>
<runcommand executable="[ -d @{dir} ]" host="@{host}" username="@{username}" password="@{password}"/>
</sequential>
</macrodef>
runcommand is just a wrapper macro for sshexec task that validates some additional stuff, but basically it’s just an sshexec.
Right now, if i run this, it works in a way that if the directory exists the build go on but if it doesn’t exist the build fails since [ -d @{dir} ] return value is 1.
I want to be able to check the return value so i can put it in a conditional tag, for example if the dir exists, skip, and if it doesn’t create it with mkdir.
Is this possible ?
This is a total stab in the dark, I don’t know if ant will let you do this. However if it’s invoking bash on the remote host, it should work.
This way if the directory exists it will short circuit and return success. If it doesn’t exist, it will call mkdir. If mkdir fails, then ant will fail.