首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ant、sudo和copynot不起作用

Ant、sudo和copynot不起作用
EN

Stack Overflow用户
提问于 2017-06-21 16:59:28
回答 2查看 591关注 0票数 1

我是蚂蚁的新手。我正在尝试使用GoCD进行简单的index.html部署。基本上,我尝试将文件从一个文件夹复制到/var/www/html (这基本上需要sudo权限)。下面是我的ant脚本:

代码语言:javascript
复制
<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,部署成功,但文件未复制为脚本。

我已尝试将复制目标替换为以下内容:

代码语言:javascript
复制
<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权限的文件夹。

EN

回答 2

Stack Overflow用户

发布于 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“属性”。

我可以建议您尝试以下几点:

代码语言:javascript
复制
<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

票数 0
EN

Stack Overflow用户

发布于 2020-04-22 11:06:25

"sudo cp“可以这样实现:

代码语言:javascript
复制
   <exec executable="/usr/bin/sudo">
        <arg value="cp"/>
        <arg value="${name}.war"/>
        <arg value="${deploy.path}"/>
    </exec>

它不是x平台/可移植的,但是可以为linux做这项工作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44671424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档