Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity Current Date variable in MMdd format

In TeamCity is there an easy way to get a variable for the current date in the format MMdd (eg 0811 for 8-Aug)?

My google-fu did not turn up an existing plugins. I looked into writing a plugin, but not having a jdk installed, that looks time consuming.

like image 410
Robert Wagner Avatar asked Aug 11 '11 01:08

Robert Wagner


1 Answers

This is quite easy to do with a PowerShell build step (no plugin required) using the following source code:

echo "##teamcity[setParameter name='env.BUILD_START_TIME' value='$([DateTime]::Now)']" 

or (for UTC):

echo "##teamcity[setParameter name='env.BUILD_START_TIME' value='$([DateTime]::UtcNow)']" 

This uses TeamCity's Service Message feature that allows you to interact with the build engine at runtime e.g. set build parameters.

You can then reference this build parameter from other places in TeamCity using the syntax %env.BUILD_START_TIME%

The advantage of this approach is you don't need to use a plugin. The disadvantage is you need to introduce a build step.

like image 130
Jack Ukleja Avatar answered Sep 22 '22 06:09

Jack Ukleja