Dynamic change to "teamcity.build.branch"

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

Is it possible? It appears that the value is evaluated and used at the beginning of the assembly pipeline.

UseCase:

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

I already use the messaging service to overwrite the parameter, but this change is not taken into account. It seems that the value is being read at the very early stage of the build process.

+6
source share
2 answers

Check below link containing build number and git branch name

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

+1
source

You can overwrite the parameter value using a simple script that issues a "set parameter" service message .

Using a special service message in your build script, you can dynamically update the build parameters to the right of the build phase (...)

With this approach, do the following:

In the first assembly configuration, define a custom assembly parameter and set its value for the unique number that you generate. Do this directly from a script that generates a unique number by writing something like this to STDOUT:

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

In the dependent assembly configuration, you now have access to this parameter. Using the second build of the script, you can overwrite teamcity.build.branch using the same mechanism:

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

Note 1: I recommend that you do not overwrite the built-in parameters, because this can have strange side effects. Rather, define a custom parameter in the second assembly configuration and use it for visualization purposes.

Note 2: If you decide to ignore Note 1, you may need to overwrite the assembly parameters by setting the dependency property as described in the documents in the section "Overriding Dependency Properties":

 ##teamcity[setParameter name='reverse.dep.*.teamcity.build.branch' value='the new value'] 
+2
source

All Articles