如何让Ant任务“SSHExec”运行命令并在完成之前退出?

时间:2014-05-01 17:32:31

标签: ant

我有一个ant构建脚本,它连接到远程服务器并使用SSHExec启动本地构建。这个构建大约需要1分钟,它会在完成后向我发送一封电子邮件,但是我的蚂蚁任务是:

<sshexec
   host="${deploy.host}"
   username="${deploy.username}"
   trust="true"
   keyfile="${user.home}/.ssh/id_rsa"
   command="~/updateGit.sh"/>

将等到脚本完成。我试过像这样传递&(我假设我必须在build.xml中转义它):

<sshexec
   host="${deploy.host}"
   username="${deploy.username}"
   trust="true"
   keyfile="${user.home}/.ssh/id_rsa"
   command="~/updateGit.sh &amp;"/>

但这似乎没有什么区别。如果这个额外的细节可以帮助任何人,脚本会产生大量的输出,并且缓慢的互联网连接会导致脚本花费更长的时间(因为它的输出正在被输送回来,这种方法的假设是我只关心它完成之后的输出,所以如果我将其打包成电子邮件,我可以监控我的收件箱,因为构建开始,基本上它是一个穷人的持续集成)

1 个答案:

答案 0 :(得分:2)

使用this answer(和nohup命令)中的信息,我按如下方式更新了我的任务:

<sshexec
  host="${deploy.host}"
  username="${deploy.username}"
  trust="true"
  keyfile="${user.home}/.ssh/id_rsa"
  command="nohup ~/updateGit.sh &gt; /dev/null 2&gt; error.log &lt; /dev/null &amp;"/>