I’ve been using TeamCity for a short while now at my new job. it seemed like there’s nothing it can’t do for me.
I decided I want to get a timestamp generated and incorporated into the build number. However, that seemed a bit more difficult than i thought.
A quick search shows a couple of options:
- Date Build Number Plugin
- It sets the entire build number to the timestamp, so you can’t put anything else there, like the VCS revision, build counter or Maven version number.
- Installation is kinda funky, having to dilddle with TC configuration files.
- Groovy Plug
- This plugin provides the build start timestamp as a parameter, which is great
- The timestamp format isn’t easily configurable
- Installation is again non-standard
- The plugin notes say it’s a bit of a memory hog, and it was meant as a demo anyway
So I just wrote my own.
Formatted Date Parameter provides a confguration parameter (named build.formatted.timestamp), which during build will contain the build start timestamp. The timestamp format is ISO-1806 by default (“yyyy-MM-dd’T’HH:mmZ”). The timestamp format can be configured using another configuration parameter (named build.timestamp.format), which uses standard SimpleDateFormat syntax.
Just like the guide says
- Copy the zip (see link at bottom of page) to the .BuildServer/plugins dir (for me it was /home/username/.BuildServer/plugins)
- Restart the Tomcat instance your TeamCity WAR is deployed to.
In my case, I wanted the week-in-year (01-52) to appear in the build number, so I
- Added build.formatted.timestamp to the build number format field (build configuration -> general settings page)
- Then I set the value of build.timestamp.format to show only the week number in 2 digits “ww” (build configuration -> build parameters page -> Add configuration parameter button)
- Now my build number contains the current week number. Hurray.