12

As the first step in a build configuration I am trying to dynamically change a parameter and use it in the subsequent steps. Reading online, it seems that the way to do this is to call ##teamcity[setParameter. But this doesn't seem to be working. It doesn't even change the value in the same step.

For example, I have created a test parameter and set it's default value to '1'. Inside a powershell script, I tried to change it to 2, as shown below.

enter image description here

But the output remains unchanged as can be seen below

enter image description here

I am currently using TeamCity 8.0.3 (build 27540). What am I doing wrong?

1 Answer 1

22

EDIT: I think the problem might be the command you're using to set the parameter. Try:

Write-Host "##teamcity[setParameter name='TestParameter' value='2']"

--

We've experienced the same behavior. The key here is 'subsequent steps.' You must modify the parameter in a separate build step that is run before the step in which you want to use the new parameter.

It's my understanding that all parameters in a build step are evaluated immediately before the execution of that step. The tokens will be replaced with the unmodified values of those parameters. Thus, what actually gets executed by the build agent is:

Write-Host "TestParameter value is 1"
Write-Host "##teamcity[setParameter name='TestParameter' value='2']"
Write-Host "TestParameter value is 1"
6
  • No, that wasn't it. I copied the step and removed the last two lines. This way, I am just "Write-Host"ing the TestParameter value. It is still printing '1'. In fact this was the original problem I had where changes in one step weren't showing up in subsequent steps.
    – Chaitanya
    Mar 4, 2014 at 6:59
  • I updated my answer to include a parameter update command that should work in PowerShell. I think everything else in the answer holds true.
    – John Hoerr
    Mar 4, 2014 at 17:19
  • Nope. It just prints it out to the log. I have also tried it with an '=' symbol between TestParameter and '2'. No go. Doesn't change the value in subsequent steps either. This is what shows up [10:11:02][Step 1/27] TestParameter value is 1 [10:11:02][Step 1/27] ##teamcity[TestParameter='2'] [10:11:02][Step 1/27] TestParameter value is 1
    – Chaitanya
    Mar 5, 2014 at 0:12
  • Third time's a charm; see the updated Edit. I tested it and it works to change the value for subsequent build steps.
    – John Hoerr
    Mar 6, 2014 at 18:10
  • Yup. That was it. I had tried that combination before, but I was still checking in the same step, which doesn't work as you said. But using this, it now shows the same value in the same step, but the updated value in a different step
    – Chaitanya
    Mar 7, 2014 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.