5

In TeamCity 9 I have two build configurations: A, B which depends on A (snapshot dependency). Sometimes A starts alone, sometimes in chain with B. I want to change build.number of A to (for example) 0.<build.counter of B> when A triggered by B.

According to docs:

Since TeamCity 9.0, there is a possibility to override the dependencies parameters by redefining them in the dependent build. For example, build configuration A depends on B and B depends on C; A has the ability to change parameters in any of its dependencies using the following format:

reverse.dep.<btID>.<property name>

Ok, I created configuration parameter in B: reverse.dep.A.build.number=0.%build.counter%. So, when I start the build chain I suppose build.number of A will changed to 0.123 (for example, build.counter of B equal to 123), but instead the string 0.%build.counter% has been passed to A and A uses own property build.counter.

How to pass exactly values of TeamCity parameters?

Gendolph
  • 463
  • 7
  • 12

2 Answers2

4

By the time "A" build starts, the "B" build is still in queue and so there is no build number available. The %build.number% parameter could not be resolved and was passed literally.

Try creating the "C" configuration and add a snapshot dependency on it (from both A and B). Set build number format in both A and B to %dep.C.system.build.number% This way you will have A and B share same counter.

Nikita Skvortsov
  • 4,768
  • 24
  • 37
  • This way I always will have `build.number` of C configuration in A. And it will incremented each time A starts. But I need counter incrementation only when A triggered by B configuration (not by human). – Gendolph Apr 27 '15 at 06:45
2

Consider question
There is no way to pass value to dependency build with reverse.dep. syntax.

reverse.dep parameters values are passed down the dependency chain as is.

(from here: https://youtrack.jetbrains.com/issue/TW-40772)


Consider problem

  1. Create configuration "C"
  2. Add to "C" snapshot dependency from "A" with "Do not run new build if there is a suitable one" option
  3. Add to "C" snapshot dependency from "B" without same option.
  4. Pass parameter from "B" to "A" through reverse.dep.A.use_C_number=true, so "A" knows what counter to use.
  5. Use this parameter in script (new build step) in "A", for example (PowerShell):

    # Gets build.number of "C"
    $C_num = "%dep.C.build.number%"
    
    # Gets 'use_C_number' parameter
    $use_C_number = "%use_C_number%"
    
    # Change current build.number if needed
    if ($use_C_number -eq "true") {
      Host-Write "##teamcity[buildNumber '1.2.3.$C_num']"
    }
    

In this case "C" will be triggered only by "B" and not by "A", because "A" will always use "suitable" build of "C" ("C" has no VCS root attached).
Note: it should be at least one finished build of "C".
Note: I'm not sure about "suitable" build in all cases, because documentation is not clear for situation with no VCS root attached to build configuration, but it works. In any case there is a question in TeamCity tracker.

So, C's build.counter will be incremented only when "B" is queued. When "A" started alone it use default build.number.

P.S. Thanks to Nikita Skvortsov for targetting me to the solution.

Gendolph
  • 463
  • 7
  • 12