I am trying to use ant to run a bash script.
Ive found that the exec directive is the tool for the job
I created a bash script test.sh and in my ant target i added:
<project basedir=".">
<property name="temp.deployment.dir" value="temp_deployment_dir"/>
<property name="temp.dir" value="temp_upload_dir"/>
<property name="src.dir" value="www"/>
<property name="js.dir" value="${src.dir}/public/js"/>
<property name="css.dir" value="${src.dir}/public/css"/>
<property name="img.dir" value="${src.dir}/public/images/"/>
<target name="clean">
<delete dir="${temp.dir}"/>
</target>
<target name="update-statics">
<mkdir dir="${temp.dir}"/>
<!--TODO: add statics in -->
</target>
<target name="deploy">
<mkdir dir="${$temp.deployment.dir}"/>
<copy todir="${temp.deployment.dir}">
<fileset dir="${src.dir}"/>
</copy>
<exec executable="bash" newenvironment="false" dir=".">
<arg value="cmd_update.sh"/>
</exec>
</target>
</project>
I get build successful when i run it, but the test.sh is never run.
I have googled and searched for what I could be doing wrong but because there is no error I am having trouble debugging it. Does anyone know the proper usage of the exec directive or if there is something I am clearly doing wrong. From What I can tell I am doing it the same as ever other exa开发者_运维问答mple of exec I have found.
If you have the shebang in your Bash script, and your script is executable, you don't need to include bash
as the command. (I am, of course, assuming Linux, Unix, or Mac).
<exec executable="${path.to.command}/cmd_update.sh"
failonerror="true"
osfamily="unix"/>
Always set failonerror
to true and always set osfamily
.
There maybe other things you want to set like the property where STDOUT and STDERR are stored. You can also pass parameters via the <arg value>
sub-tasks.
I would not use the searchpath
parameter since that could be a security hole.
First things first - I usually cringe when I see an exec, it's usually something smelly. You want to set failonerror to 'true' when using exec, and make sure your script is exiting with a proper return code where appropriate.
You also don't need to call bash, you can call the script directly - make sure it's executable.
The output of ant -v would be relevant.
Try:
<exec executable="**/bin/**bash" newenvironment="false" dir=".">
<arg value="cmd_update.sh"/>
</exec>
精彩评论