Passing parameters from one build step to the next one

I have 2 build steps, A and B.

B is based on a meta-runner, and expects a parameter %param%. This meta-runner is used independently of A, in another context.
A is a Powershell script, that computes this parameter dynamically.

I cannot find an elegant way to do this with TeamCity 8.

Doing this in A :
echo "##teamcity[setParameter name='param' value='my value']"

doesn't work, probably because while A sets it correctly, but %param% is overwritten by the empty value defined in the configuration of B when B is started.

I tried also to set param to %param% in the configuration of B,  hoping the value from A would be reused, but that's not the case. The build cannot be even started because TC looks for an agent for which param would be defined.

So I ended up working with environment variables as a workaround:

In A:
echo "##teamcity[setParameter name='env.param' value='my value']"

In B:
if ( $Env:param ) {
  # param set by environment variable, e.g. from previous build step
  $param = $Env:param
else {
  # param NOT set by environment variable, used build step parameter instead
  $param = "%param%"

But I don't like the use of environment variables.

Is there a more elegant way ?

Comment actions Permalink

Can anyone help me ?

Comment actions Permalink

Thanks a lot for sharing this. I'm struggling with the same problem.
The solution from the support with 2 additional configs seems to complicate things. It's a mess to remember what of them should be run.


Please sign in to leave a comment.