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.
Installation:
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.
Usage:
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.
FormattedDateParameter v1.1 plugin for TeamCity (download) (source on github)
It works but with default yyyy-MM-dd’T’HH:mmZ
build configuration -> build parameters page -> Add configuration parameter button – this not set assumed date format
Right, if you don’t provide a date format pattern using build.formatted.timestamp, the plugin will revert to the default (ISO-1806).
Nice one. Really useful.
Hi,
I am using this plugin in TeamCity. How can i change the default format to ‘yyyy.MM.dd.HH.mm’ using Build configuration->Add Paramters.
Please help.
If you go into the build configuration’s settings page and then go into Parameters you can add a parameter to the build configuration, you can then add a parameter named build.formatted.timestamp, in which you can specify the format you wish to use.
Very nice!
Thank you!
This was JUST the plugin we needed! We do builds weekly, so they have a specific numbering scheme (year.week.build-number) and this was very helpful. Thank you!
Hi Bruce,
Do you have any workaround right now?
Regards,
Jason
Awesome work Daniel!!
Thank you so much for this plugin!
Tnx
Hi Dan,
I have created a configuration parameter for the build with name build.formatted.timestamp and values as yyy.MM.dd
But that doesn’t seem to work. I am using TeamCity 9.1. Would you be able to help here?
Thanks in advance.
Hi Altaf,
The format string should be put into the variable build.timestamp.format, and then you can use build.formatted.timestamp in other fields in the builds without populating it yourself (the plugin will take care of that for you).
Hope this helps 🙂
How does this handle ISO 8601 week numbers? I know .NET has some quirks I had to write around before, but unsure if Java has this issue.
This plugin uses Java’s SimpleDateFormat to convert the timestamp into a formatted string, so googling “SimpleDateFormat ISO 8601” should be all you need.
Any recommendation for how I would use two different formats in the same build configuration (e.g. one for the copyright year yyyy and one for a full timestamp yyyy-MM-dd’T’HH:mmZ). Do I need to create a dependent build configuration with the second format and reference that dependent parameter?
You could probably do that in a pinch, but you (or I if I find the time) could add to the plugin variables like build.timestamp.format2 and build.formatted.timestamp2 (or more) and send me a pull request on github (here: https://github.com/minodudd/TeamCity-plugins)
Daniel, Thanks for Plugin!
can you publish latest build of plugin packaged for TeamCity as Zip?
I would like to use build.date.dd, build.date.mm, build.date.yyyy, build.date.yy, etc… Maybe “kk.mm” time parameter is good to have too.
Also It is handy to use “build.timestamp.format2” and “build.formatted.timestamp2” as far as you support this original conception.
Hi,
I want it to produce ‘yMMdd’ from the current date. So only the last digit of the year.
For example from 2016/04/06 I want ‘60406’.
Is that possible? Thank you
Looks like SimpleDateFormat doesn’t support this, so using a single “y” would produce a 4-digit year, you could use “yy” to produce a 2-digit year (2016 -> 16), but they don’t support single digit.
I’m afraid what you’re asking is not possible with this plugin.
Hi, how I can specify the month in upper case so 6th June 2016 will be 06_JUN_2016. Currently I am getting 06_Jun_2016 with
I’m afraid SimpleDateFormat doesn’t seem to support this.
It was helpful. Thanks.
Today we run TeamCity with your plugin and the result was 17.12 (having the format like YY.MM). It must be created somethink like 16.12.
Have you any idea what could be wrong? Could this be a bug? Java problems?
Thanks!
Hi,
Groovy plugin provides %system.build.start.date% parameter and it gives me the value of 20170118.
Is that possible to add a symbol in between like 2017-01-18 by using FormattedDateParameter v1.1 plugin?
Thanks.
Hi, I was trying to get this plugin to work on TC 2017.4. Installed the plugin, rebooted all agents. When I try to use the build.formatted.timestamp parameter, I am unable to pick up any agents because:
Implicit requirements:
build.formatted.timestamp defined in Build number pattern
Any idea what would cause this?