2017-06-21 118 views
0

我是一個新手在螞蟻。我正在嘗試使用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權限的文件夾。

+0

請仔細閱讀[?在什麼情況下我想補充「緊急」或其他類似的短語我的問題,爲了獲得更快的答案](// meta.stackoverflow.com/q/326569) - 總結是,這不是解決志願者問題的理想方式,而且可能對獲得答案起反作用。請不要將這添加到您的問題。 – halfer

回答

0

如果您查看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的