In this post I describe how one could transfer environment from one build step to another
Suppose you have a build script (.sh or .bat) that patches, adds, or updates environment variables to prepare things for the build. It looks handy to use TeamCity runners, but it could be a real pain to specify all such variables explicitly.
Our goal is to make TeamCity build have the same updated environment variables for all build steps.
Implementation is really simple. In the example I use vcvarsall.bat from Visual Studio 2010 to update environment variables. To call the script I use Command Line build runner's Custom Script:
*Here I use %env.TEAMCITY_CAPTURE_ENV% instead of %TEAMCITY_CAPTURE_ENV% only because TeamCity pre-processes %references%. So if you use do not use TeamCity's Command-Line runner Custom Script, you need to simply put %TEAMCITY_CAPTURE_ENV%
The trick is that TeamCity provides environment variable called TEAMCITY_CAPTURE_ENV. This variable contains a path to an executable program that reports current environment variables back to TeamCity as service messages
Changes in build variables are also show on Build Parameters tab of finished build:
In general, you may use those service messages to change any parameters of build, including configuration parameters, system properties or environment variables.
You may use this trick starting from TeamCity 7.0
comments powered by Disqus