0

I have a build chain that has seven builds in it.

First there is the Starter build. Starter build has a snapshot dependency on two Package builds (client and server). Each package build has two snapshot dependencies, one on Cook build and another on Compile build (so there are two cook and two compile builds in the chain).

What I'd like to have is a common and unique number in each build chain that with which I can mark individual builds and use it to synchronize some things that are on build agents (but not managed by teamcity).

I also need to be able to run package build themselves

I've tried three things:

  1. reverse dependencies - have a %custom.buildNumber% parameter in every build except the starter one and define a %reverse.dep.*.custom.buildNumber% = %teamcity.build.id% in the starter build. This unfortunately does not work because reverse dependencies are resolved after they are sent to the builds, not prior, so each build would get it's own %teamcity.build.id% instead of starter ones.
  2. number generator build - have an additional composite build with build reuse turned on that every build in the chain snapshot depends on and then reference %dep.numberGeneratorBuild.teamcity.build.id% wherever I need the number in the chain. This works for most cases, but it's not truly unique - if you start two build chains with the same vcs change, both of them will get the same number, which is a deal breaker.
  3. triggeredBy and REST api - each build has a %teamcity.build.triggeredBy% parameter that, if build was triggered by snapshot dependency, holds, among other things, the build number of the build that triggered it. However, you cannot use this value directly, you have to parse the string in a build step. You can then use the REST api to get to the build that triggered it, see if it was triggered by another and go up the chain until you get to the build that started it all. This would ensure you always get a unique ID for every chain (especially if you set buildNumberFormat to %teamcity.build.id% which is incremented for each build on the teamcity server. The problem with this approach is that I want to use this identifier as the build number. I can create a %custom.buildNumber% parameter and use powershell to set it to the %teamcity.build.id% I figured out using the REST api. In theory, if I set buildNumberFormat = %custom.buildNumber% it should all work, right? Well, no, becuase buildNumberFormat is resolved at the start of the build when this parameter is still unset, and even if I figure it out in the first step, it wouldn't update the builds build number that is displayed in the teamcity UI (leaving each build with build nubmer set to #???).

So there are all my attempts. The first one doesn't work at all, the second one doesn't provide the unique ID and the third one can't be applied to the UI making all builds have build number#??? which makes it really hard to see what is what.

Other than pestering team city developers to put in a feature (that has first been requested 15 (fifteen!) years ago and consistently ever since), do you have any ideas on how I could have a number that is both:

  • unique for each build chain run, even if on same vcs change
  • accessible to each build in the chain at the very start of the build?

Thanks in advance!

0 Answers0