I'm using nAnt to automate my projects' build and release. That means from time to time I will write about my experience with automatic building and releasing, and interesting things I find in the process.
Today I had to solve a small problem in a nAnt scripts. I needed to timestamp archive of the release. While nAnt zip task can timestamp the file, the format it uses (MM/DD/YYYY HH:MM:SS) is not suitable for me. I prefer for the project release date to be a part of the version and to follow minor version (i.e. 0.5.20051004). I'm sure there are arguments for and against using such version format, but I like this and I wanted to solve specific problem of generating it.
This is what I came up with:
<property name="date.now" value="${ datetime::now() }"/>
<property name="year.now" value="${ datetime::get-year( date.now )}"/>
<property name="month.now" value="${ datetime::get-month( date.now )}"/>
<property name="month.now" value="0${ month.now }" if="${ int::parse( month.now ) < 10 }"/>
<property name="day.now" value="${ datetime::get-day( date.now )}"/>
<property name="day.now" value="0${ day.now }" if="${ int::parse( day.now ) < 10 }"/>
<property name="timestamp" value="${year.now}${month.now}${day.now}"/>
timestamp property will have current date in YYYYMMDD format. It can be used to timestamp the archive (what I'm using it for), to generate build number, etc.
This is an example of how you could use it to timestamp zip archive:
<zip zipfile="${release.dir}\${project.name}.${timestamp}.zip">
<fileset basedir="${working-release.dir}">
<include name="**" />
</fileset>
</zip>
Some of the properties, like release.dir must be initialized earlier, but I wanted to keep example simple so I omitted all initialization.
If you find a simpler way to generate timestamp let me know. I'd be delighted to hear about it.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5