How can I make a build number based on the dependencies' build numbers?

Our installer configuration depends on several program components, which are built in separate configurations. They all use different vcs roots. This means the build number of the installer reflects the latest change to the installer itself, not the latest change to the included components.

I am trying to set up a custom build number that fixes this issue, and my first idea was to use a python build step to iterate over the build numbers of all the dependencies and selecting the largest. This however requires me to pass all those in manualy, which is far from ideal. When someone copies the project (as we do when we create a new branch), they would have to update these manually, which they will forget. It's a long shot, but is there some way of passing several properties to the build step? Something like %dep.*.build.number%?

Another option would be for each configuration to create a file containing the build number, and add this to the artifacts. The installer could then iterate over the these files to set its build number. This has the advantage that no manual updates are needed after copying a project.

Since option one is probably impossbile and  option two is cumbersone, do you have any other idea for how to do this? Ideally, this would be a TeamCity property, something like %build.largest_dependency_number%.

1 comment
Comment actions Permalink

I made a Python script that does this:

From the documentation:

This script will set the TeamCity build number of a configuration to
max(dependencies_build_numbers + [own_build_number])

Say you have an installer configuration, which depends on the module1 and
module2 configurations. Let the installer have vcs number 100, and module1 have
vcs number 103. Then the installer build number will be 100, but we want it to be

How to use:
-In the artifact paths of all the configurations that should influence the final
build number, add "vcsnumber*.txt =>"
-In the artifact dependencies of all the configurations that should be
influenced by its dependencies, add "!*.* =>"
-In all of the above, add a build step that calls this module.

What happens:
For a configuration that has no dependencies, this script just saves the
current build number to 'vcsnumber_CONFIGURATION_NAME.txt' This file is then
included in the artifacts for that configuration.
For a configuration that has dependencies, the artifact dependencies copy all
the vcsnumber_CONFIGURATION_NAME.txt files, and find the largest build number
from those. It then selects the largest number of those and its own build
Finally the script writes out "##teamcity[buildNumber 'COMPUTED_NUMBER']"
This message tells TeamCity to update its build number to the one that was
computed by this script.

Please sign in to leave a comment.