Mathias Fernström
Mathias Fernström

Reputation: 173

Teamcity, set configuration parameter for next build

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

Upvotes: 6

Views: 6751

Answers (3)

zuba
zuba

Reputation: 1508

You can reference MyVariable variable which you set in Build configuration 1 in a script in Build configuration X such way: %dep.BuildConfiguration1Id.MyVariable%

Upvotes: 1

BrokenGlass
BrokenGlass

Reputation: 160852

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.

Upvotes: 4

infojolt
infojolt

Reputation: 5408

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

Upvotes: 2

Related Questions