TeamCity Current Date variable in MMdd format

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.


For Unix based build agents I propose next custom script as one of build commands:

export current_build_date_format="+%%Y.%%m.%%d"
export current_build_date="$(date $current_build_date_format)"
echo "##teamcity[setParameter name='env.current_build_date' value='$current_build_date']"

You have to make double % sign to avoid interpretation for date executable command line argument FORMAT string (see %Y.%m.%d) as already existing TeamCity variable.