Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity, passing an id generated in one build step to a later build step

Tags:

teamcity

New to TeamCity. I have multiple build steps. Step 3 generates an id that is needed in step 4. What is the best way to pass the id (a string) between step 3 and step 4? The build steps are written in Ruby. Can I set an environment variable?

like image 221
Mike Jr Avatar asked Nov 21 '11 22:11

Mike Jr


People also ask

What is build ID in TeamCity?

teamcity.buildType.id. none. The unique ID used by TeamCity to reference the build configuration the current build belongs to.

How do you set building steps in TeamCity?

In Build Steps, click Auto-detect build steps, and then select the proposed steps you want to add to the current build configuration. You can change their settings afterwards. When scanning the repository, TeamCity progressively searches for project files on the two highest levels of the source tree.

What is parameter in TeamCity?

Last modified: 04 August 2022. Build parameters are name-value pairs, defined by a user or provided by TeamCity, which can be used in a build. They help flexibly share settings and pass them to build steps.


1 Answers

Yes, you can set an environment variable in one build step and use it in the following step. You will need to use a service message in your build script as described here http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-AddingorChangingaBuildParameterfromaBuildStep to dynamically update a build parameter, which you can use in the next step. Note, that it won't be available in the step that generates it, only in the next one.

Note that to set the variable, it must be written out somehow (echo for bash command-line, write-host for Powershell), in quotes. Example:

echo "##teamcity[setParameter name='env.ENV_AAA' value='aaaaaaaaaa']"

and to use this variable write %env.ENV_AAA% in the box in the next build step (Atleast in TeamCity 9.1.7))

like image 66
Maria Khalusova Avatar answered Oct 22 '22 13:10

Maria Khalusova