2016-05-17 19 views
1

私のローカルオフィスネットワークとAWSの両方で動作するようにAnt build.xmlスクリプトを修正しようとしています。そのため、どこでビルドが行われているかによって、別のivysettings.xmlファイルを使用する必要があります。どちらの場合も、Jenkinsでビルドが開始されます。私の考えは、AWSから開始されたときにプロパティ 'aws = true'を挿入し、それ以外の場合はプロパティを持たないことでした。私たちはAWSでAnt 1.7.1のローカル版と新しい版を使用していますが、どちらの版でbuild.xmlを実行できるのかは分かりませんので、1.7.1が限界です。私は必要に応じてこれをアップグレードすることができます。Antの条件付き設定ファイル

この目的のためにこのbuild.xmlファイルを修正するために必要な構文を教えてもらえますか?

<!-- Resolve dependencies --> 
<target name="resolve" description="retrieve dependencies with ivy"> 
    <ivy:settings file="ivysettings.xml"/> 
    <ivy:retrieve sync="true"/> 
</target> 

真AWS =私はivysettings_aws.xmlと呼ばれるファイル、他のivysettings.xmlを使用したい場合。

ありがとうございます。

答えて

0

私はant_contribを使ってこれを理解しました。

<!-- Resolve dependencies --> 
<target name="resolve" description="retrieve dependencies with ivy"> 
    <if> 
     <equals arg1="${aws}" arg2="true" /> 
     <then> 
      <ivy:settings file="ivysettings_aws.xml"/> 
     </then> 
     <else> 
      <ivy:settings file="ivysettings.xml"/> 
     </else> 
    </if> 
    <ivy:retrieve sync="true"/> 
</target> 

作品。

0

以下は簡単ですか?次のように

代替設定ファイルが指定されている

<property name="ivy.settings" value="ivysettings.xml"/> 

<target name="resolve" description="retrieve dependencies with ivy"> 
    <ivy:settings file="${ivy.settings}"/> 
    .. 
</target> 
:。

ant -Divy.settings=ivysettings_aws.xml .. 
+0

いいね、ありがとう!それはより簡単です。 cmd行は宣言を上書きするでしょうか? –

+0

@ eric-gはい、コマンドラインで設定したプロパティは、ANTファイル内のデフォルト値を上書きします。 –

0

あなたがところでサービスの外にあるantcontribに追加の依存関係を取り除くためにnew if/unless feature introduced with Ant 1.9.1を使用する必要があり、latest release 1.0b3ほぼ10年前。以下のような
何か:

<project 
    xmlns:if="ant:if" 
    xmlns:unless="ant:unless" 
> 

<!-- Resolve dependencies --> 
<target name="resolve" description="retrieve dependencies with ivy"> 
<ivy:settings file="ivysettings_aws.xml" if:true="${aws}"/> 
<ivy:settings file="ivysettings.xml" unless:true="${aws}"/> 
<ivy:retrieve sync="true" /> 
</target> 

</project> 

またマーク・O」コナーによって提案されたソリューションを使用していますが、あなたのニーズを満たすために-Divy.settings=...パラメータの変更覚えておく必要があります。