我正在做一些類似的構建腳本。基本上創建一個屬性文件,我將其作爲資源放置在源文件夾中。這裏的片段:
<target name="init">
<!-- Format the build number to a 4 figures integer with leading zeroes if required -->
<!-- The build number is also incremented by 1 -->
<propertyfile file="${build.number.file}">
<entry key="build.number" type="int" default="0000" operation="+" pattern="0000" />
</propertyfile>
<!-- Read the build number -->
<property file="${build.number.file}"/>
<!-- create the build date and time with time zone -->
<tstamp>
<format property="readable.now" pattern="yyyy-MM-dd hh:mm z"/>
</tstamp>
<!-- Write thebuild and version information to a resource file -->
<!-- The resource file will be part of the corresponding jar -->
<propertyfile file="${node}/src/resources/META-INF/jppf-version.properties">
<entry key="version.number" type="string" value="${version.number}"/>
<entry key="build.number" type="string" value="${build.number}"/>
<entry key="build.date" type="string" value="${readable.now}"/>
</propertyfile>
</target>
生成的文件是這樣的:
#Wed, 30 Apr 2014 07:45:12 +0200
version.number=4.2 alpha
build.number=1352
build.date=2014-04-30 07\:45 CEST
顯然,一些你需要的數據是不是在那裏,但是你可以很容易地將其添加爲<entry>
元素,使用作爲值的對應的的名稱,例如:
<propertyfile file="${path.to}/versionbuild.txt">
<entry key="build_number" type="string" value="${build.number}"/>
<entry key="date_of_build" type="string" value="${readable.now}"/>
<entry key="jdk_compiler" type="string" value="${java.vm.version}"/>
<entry key="jdk_compiler" type="string" value="${os.name}"/>
<entry key="build_person" type="string" value="${user.name}"/>
</propertyfile>
什麼是versionbuild.txt?這與詹金斯有關嗎? –