我是蚂蚁的新手。我正在尝试使用GoCD进行简单的index.html部署。基本上,我尝试将文件从一个文件夹复制到/var/www/html (这基本上需要sudo权限)。下面是我的ant脚本:
<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>这里抛出的错误类似于"BUILD FAILED /var/lib/go-agent/pipelines/Test-Pipeline/build.xml:5: copy copy the "if“attribute”
谁能帮帮我,因为我被困住了,没有正确的方向可走。我想要实现的是将文件复制到具有sudo权限的文件夹。
发布于 2017-06-22 05:56:15
如果您查看Copy task上的Ant文档,您会注意到在'Parameters‘下和'Attributes’列下,在对复制任务的调用中不支持' If‘属性-因此您会收到错误消息:"BUILD FAILED /var/lib/go-agent/pipelines/Test-Pipeline/build.xml:5: Copy不支持"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任务,而不是在对复制任务的调用中嵌入'if‘条件(因为它不受支持)。
*注意:此方法确实需要使用Ant Contrib
发布于 2020-04-22 11:06:25
"sudo cp“可以这样实现:
<exec executable="/usr/bin/sudo">
<arg value="cp"/>
<arg value="${name}.war"/>
<arg value="${deploy.path}"/>
</exec>它不是x平台/可移植的,但是可以为linux做这项工作
https://stackoverflow.com/questions/44671424
复制相似问题