TeamCity Current Date variable in MMdd format

烂漫一生 提交于 2019-12-02 18:11:03
Bilal

The Groovy Plugin for TeamCity provides build start date/time properties:

Provides build properties:

system.build.start.date / env.BUILD_START_DATE

system.build.start.time / env.BUILD_START_TIME

This blog post has installation / configuration instructions for the Groovy plugin, as well an example of customizing the date/time 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.

You can also try Date Build Number plug-in. It povides additional var in build number format rather than build property.

To add a dated folder to my build in TeamCity I added the following to my custom script. What had me stuck was the double % sign in the date string. D'oh

TARGET_DIR=/Users/admin/build/daily
TARGET=$(date "+%%Y-%%m-%%d")

if [ ! -d ${TARGET_DIR} ]; then
  mkdir -vp ${TARGET_DIR}/
fi
mv -v build.dmg ${TARGET_DIR}/build_${TARGET}.dmg
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!