在设计配方,我们建议您创建环境无关(environment agnostic )的服务描述符文件,以便配方可以运行在不同的环境。这是很容易实现使用Groovy属性(properties )文件来定义键,您可以将其作为参数使用在你的服务描述符文件。
properties文件必须与服务描述符文件保存在同一文件夹,并且建议使用以下命名约定: <myRecipe>-service.properties
(e.g. jboss-service.properties).。定义的键使用一个简单的 Key=Value
形式(e.g. myKey=myValue
)并可用于DSL闭包的字符串参数,它们也可以以$ {key}符号(e.g. ${myKey}
)被用于其他字符串。
以下为一个示例,属性文件和对应的服务描述符文件的一部分,使用定义的key作为参数。
version = "5.5.0"
name = "apache-activemq-${version}"
zipName = "${name}-bin.zip"
installDir = "install"
downloadPath = "http://apache.spd.co.il//activemq/apache-activemq/${version}/${zipName}"
script = "install/${name}/bin/activemq"
new AntBuilder().sequential {
mkdir(dir:installDir)
get(src:downloadPath, dest:"${installDir}/${zipName}", skipexisting:true)
unzip(src:"${installDir}/${zipName}", dest:installDir, overwrite:true)
//dos2unix on the linux script files
fixcrlf(srcDir:"${installDir}/${name}/bin", eol:"lf", eof:"remove", excludes:"*.bat *.jar")
chmod(dir:"${installDir}/${name}/bin", perm:'+x', excludes:"*.bat *.jar")
}