蚂蚁,sudo和copynot工作
问题描述:
我是一个新手在蚂蚁。我正在尝试使用GoCD来简单部署index.html。基本上我试图将文件从一个文件夹复制到/ var/www/html(基本上需要sudo权限)。这里是我的ant脚本:蚂蚁,sudo和copynot工作
<project name="My Project" default="help" basedir=".">
<condition property="rootTasksEnabled">
<equals arg1="ec2-user" arg2="root" />
</condition>
<target name="copy" description="Copy New Web Page" if="rootTasksEnabled">
<copy file="/var/lib/go-agent/pipelines/Test-Pipeline/index.html" todir="/var/www/html"/>
</target>
</project>
我想建立这样的build.xml,部署成功,但作为脚本文件是不可复制的。
我试图与替代复制目标如下:
<project name="My Project" default="help" basedir=".">
<condition property="rootTasksEnabled">
<equals arg1="ec2-user" arg2="root" />
</condition>
<copy todir="/var/www/html" flatten="true" if="rootTasksEnabled">
<resources>
<file file="/var/lib/go-agent/pipelines/Test-Pipeline/index.html"/>
</resources>
</copy>
</project>
这里引发错误,如“建立失效 /var/lib/go-agent/pipelines/Test-Pipeline/build.xml: 5:复制不支持“if”属性“
有人可以帮助我,因为我被困在没有适当的方向去。我想实现的是将文件复制到具有sudo权限的文件夹。
答
如果您查看Copy task上的Ant文档,您会注意到在'Parameters'下并且在'Attributes'列的下面,在Copy任务调用中不支持'if'属性,因此您收到的错误消息:“BUILD FAILED /var/lib/go-agent/pipelines/Test-Pipeline/build.xml:5:副本不支持”if“属性”。
我可以建议尝试以下操作:
<project name="My Project" default="help" basedir=".">
<condition property="rootTasksEnabled">
<equals arg1="ec2-user" arg2="root" />
</condition>
<if>
<isset property="rootTasksEnabled" />
<then>
<copy todir="/var/www/html" flatten="true">
<resources>
<file file="/var/lib/go-agent/pipelines/Test-Pipeline/index.html"/>
</resources>
</copy>
</then>
</if>
</project>
而不是嵌入一个“如果”条件调用复制任务中(因为它是不支持的),另一种方法是利用的if/then任务。
*注意:此方法确实需要使用Ant的Contrib的
请仔细阅读[?在什么情况下我想补充“紧急”或其他类似的短语我的问题,为了获得更快的答案](// meta.stackoverflow.com/q/326569) - 总结是,这不是解决志愿者问题的理想方式,而且可能对获得答案起反作用。请不要将这添加到您的问题。 – halfer