Formatted Date Parameter – A Plugin for TeamCity

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

  1. Added build.formatted.timestamp to the build number format field (build configuration -> general settings page)
    using the %build.formatted.timestamp% parameter in the build number field
    using the %build.formatted.timestamp% parameter in the build number field

     

  2. 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)
    Setting the timestamp format
    Setting the timestamp format

     

  3. Now my build number contains the current week number. Hurray.

 

 

FormattedDateParameter v1.1 plugin for TeamCity (download) (source on github)

21 thoughts on “Formatted Date Parameter – A Plugin for TeamCity

  1. 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

    1. Right, if you don’t provide a date format pattern using build.formatted.timestamp, the plugin will revert to the default (ISO-1806).

  2. 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.

    1. 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.

  3. 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!

  4. 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.

    1. 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 🙂

    1. This plugin uses Java’s SimpleDateFormat to convert the timestamp into a formatted string, so googling “SimpleDateFormat ISO 8601” should be all you need.

  5. 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?

  6. 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

    1. 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.

  7. 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

Leave a Reply

Your email address will not be published. Required fields are marked *