47
votes

i am looking for a way to share build number between multiple build configurations. The goal is to have an global counter of some sort and all build configurations would be incrementing it and use it in its own the build number.

7

7 Answers

55
votes

If one of build configurations A has snapshot or artifact dependency on build configuration B, then you can obtain build number from B in A with help of dependency parameter:

%dep.<B id>.build.number%

Where <B id> is id of build configuration B (see buildTypeId parameter in URL).

39
votes

This solution works for me:

  1. Create Build Configuration. Let say "GenerateBuildNumber", do not attach template. Do not specify any build steps. Click Save.
  2. Edit configuration for your project. Go to "Build Configuration Settings->Dependencies". Click "Add new snapshot dependecy".
  3. Select previously created "GenerateBuildNumber" in "Depend on" section. Uncheck option "Do not run new build if there is a suitable one". Click Save.
  4. Go to "General Settings", clear "Build number format:", click the button on the left side with 3 lines. Select "%dep.YouProjName_GenerateBuildNumber.env.BUILD_NUMBER%". Click Save.

Run your project build. Firstly it should start "GenerateBuildNumber" project then your project with a generated number. Do the steps 2-4 for every project you want to have unique generated number. Profit!

14
votes

I believe the AutoIncrementer plugin should do the trick. It lets you share build numbers between configurations. http://confluence.jetbrains.com/display/TW/Autoincrementer

5
votes

You can make one Team City project use the build number from another project by following these steps:

  1. Open the TeamCity project configuration's properties for the configuration where you want to import the build number.

  2. Go to the "Dependencies" section.

  3. Add an "Artifact Dependency" and choose the project configuration that you want to get the build number from as the dependent project.

  4. In the "Get artifacts from" field choose "Build with specified build number"

  5. Next to the "Build number" input box there is a button you can click to choose where to get the build number. In this list you should see an option like "dep.bt2.build.number" (the number might not be 2 for your configuration).

3
votes

AutoIncrementer is good, but now there is a new plugin that has tried to do what some users said they can't do with AutoIncrementer:

http://java.nicholaswilliams.net/TeamCityPlugins/introduction#SharedBuildNumber

It has a UI when you add it to TeamCity, and can also handle the use of dates in the format that you might want to use.

0
votes

The easiest way by far is to use the variable that gets exposed: %dep.<build configuration id here>.build.number% You can use any parameter from the dependency using that variable. If you start typing % in a field with the square box next to it that lets you choose a variable it will pop up with the build configuration id there.

0
votes

How to set parameter
Step 1: Using IDE to pick up which one you want to use
enter image description here Step 2: %dep.[B id].build.number% from another project name
enter image description here

How to get parameter
enter image description here

echo %CAPR_number% <-- Parameter Name