Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Teamcity, set configuration parameter for next build

Tags:

teamcity

I'm trying to set/change a build parameter from build 1 to be used in build 2.

In build 1 I have a build step that sets a configuration parameter like this:

echo "##teamcity[setParameter name='ENVIRONMENT' value='%Target environment%']"

And in a build step on build 2, I want to use this environment variable in a rake task by specifying %ENVIRONMENT%

The problem I have is that the configuration parameter is not visible in build 2. I have surely missed something essential.

I have also tried with env variables but that seems like the wrong approach as this is just configuration variables which is not needed in a build script.

Any clues?

Thanks

like image 222
Mathias Fernström Avatar asked May 06 '14 13:05

Mathias Fernström


2 Answers

You can publish an artifact with the value you want in build 1, introduce an artifact dependency from build 2 to build 1, and in the first step of build 2 transform that artifact into a configuration value again for the other steps in build 2 by using the echo (or better Write-Host) statement you mentioned.

like image 187
BrokenGlass Avatar answered Sep 23 '22 00:09

BrokenGlass


You can solve this in the same way I did for: Is it possible to permanently update the value of a TeamCity build parameter as a result of a custom run?

Build 1 can update a variable which is being used in build 2 rather than build 2 trying to read a parameter in build 1.

Download and install CURL on build agent:

Add a command line step to build 1:

curl -v --request PUT -d "%Target environment%" --Header "Content-Type: text/plain" http://username:password@servername:8080/httpAuth/app/rest/projects/Build2Project/parameters/ENVIRONMENT

This updates the value of a parameter on a project, but you can use the REST API to update it on a particular build configuration if you prefer.

All REST.API documentation for TeamCity v8 can be found on their website

like image 45
infojolt Avatar answered Sep 25 '22 00:09

infojolt