Dynamically changing 'teamcity.build.branch'
Asked Answered
T

2

7

I want to set the value of 'teamcity.build.branch' dynamically according to the result of another TC build configuration part of the build pipeline.

Is that even possible? It looks like the value is evaluated and used at the start of the build pipeline.

UseCase:

  • I am executing a TC build configuration that will generate a unique number
  • in the connected TC build configuration part of the same pipeline I want the number to be used in the 'teamcity.build.branch' - just for visualization purposes

I am already using message service to overwrite the parameter, but the change is not taken into account. It looks like the value is read in the very early stage of the build process.

Turne answered 23/9, 2016 at 9:52 Comment(2)
Do you want a build on one branch to cause a build to be triggered on the same branch?Trueman
Updated usecaseTurne
C
2

Check below reference containing build number and git branch name

https://octopus.com/blog/teamcity-version-numbers-based-on-branches

Contrariety answered 2/10, 2016 at 11:44 Comment(1)
This looks closest to what I need.Turne
M
2

You could overwrite the value of the parameter by using a simple script that emits a "set parameter" service message.

By using a dedicated service message in your build script, you can dynamically update build parameters of the build right from a build step (...)

With that approach, here are the steps that you need to perform:

In the first build config, define a custom build parameter and set its value to the unique number you're generating. Do this directly from the script that generates the unique number by writing something like this to STDOUT:

##teamcity[setParameter name='magicNumber' value='1234']

In the dependent build config, you now have access to that parameter. Using a second build script, you can overwrite the teamcity.build.branch with the same mechanism:

##teamcity[setParameter name='teamcity.build.branch' value='the new value']

Note 1: I recommend against overwriting the built-in parameters, because this might have strange side-effects. Rather, define a custom parameter in the second build config and use that for your visualization purposes.

Note 2: In case you decide to ignore Note 1, it may be necessary to overwrite the build parameters by setting the dependency property as outlined in the docs in section "Overriding Dependencies Properties":

##teamcity[setParameter name='reverse.dep.*.teamcity.build.branch' value='the new value']
Miserly answered 26/9, 2016 at 8:29 Comment(2)
I updated the question. I am already modifying the value using message service. However the change is not taken into account.Turne
I updated the answer. If it is possible at all, then like that. I'm not 100% sure that it actually is possible, however.Miserly
C
2

Check below reference containing build number and git branch name

https://octopus.com/blog/teamcity-version-numbers-based-on-branches

Contrariety answered 2/10, 2016 at 11:44 Comment(1)
This looks closest to what I need.Turne

© 2022 - 2024 — McMap. All rights reserved.