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.

Crazyjavahacking
  • 9,343
  • 2
  • 31
  • 40

2 Answers2

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']
theDmi
  • 17,546
  • 6
  • 71
  • 138
  • I updated the question. I am already modifying the value using message service. However the change is not taken into account. – Crazyjavahacking Sep 26 '16 at 14:13
  • I updated the answer. If it is possible at all, then like that. I'm not 100% sure that it actually is possible, however. – theDmi Sep 26 '16 at 14:22
2

Check below reference containing build number and git branch name

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

Syed
  • 417
  • 1
  • 6
  • 13