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 Answers
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).

- 10,369
- 5
- 50
- 57

- 2,201
- 14
- 14
-
3Thanks, and how to get a build number of the last successful build of configuration B? – adnako Apr 04 '16 at 11:17
This solution works for me:
- Create Build Configuration. Let say "GenerateBuildNumber", do not attach template. Do not specify any build steps. Click Save.
- Edit configuration for your project. Go to "Build Configuration Settings->Dependencies". Click "Add new snapshot dependecy".
- Select previously created "GenerateBuildNumber" in "Depend on" section. Uncheck option "Do not run new build if there is a suitable one". Click Save.
- 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!

- 11,278
- 6
- 51
- 79

- 620
- 6
- 5
-
While it's a bit awkward to have to use a dedicated build configuration, this solution does work really well. I prefer not taking on plugin dependencies if I don't have to. – Eric Sondergard Apr 17 '17 at 16:55
-
-
1
I believe the AutoIncrementer plugin should do the trick. It lets you share build numbers between configurations. http://confluence.jetbrains.com/display/TW/Autoincrementer

- 4,793
- 1
- 29
- 36
-
-
1I'm successfully using it with TeamCity 8.0.2. Just download the v7 of the package. – Jeremy Smith Oct 10 '13 at 14:45
-
I couldnt get it working with on 8.1.2 using version 8 of the package. I did manage to get v31 (downloaded from jetbrains build server) working on Tc 8.1.2. – Dav Evans Jul 30 '14 at 06:31
-
1I have successfully used this with TeamCity 9.1.3 (build 37176) using the 8.x+ build.It's a little bit fiddly in that you need to manually edit the autoincrementer.configuration file, but seems to work fine. – PabloInNZ Oct 29 '15 at 00:17
-
You can make one Team City project use the build number from another project by following these steps:
Open the TeamCity project configuration's properties for the configuration where you want to import the build number.
Go to the "Dependencies" section.
Add an "Artifact Dependency" and choose the project configuration that you want to get the build number from as the dependent project.
In the "Get artifacts from" field choose "Build with specified build number"
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).

- 2,236
- 23
- 30
-
-
This worked for me with "Get artifacts from": "Last successful build". – giraffe.guru Dec 20 '17 at 00:31
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.

- 1,268
- 16
- 25
-
1This link doesn't work. http://java.nicholaswilliams.net/TeamCityPlugins/introduction#SharedBuildNumber – koerbcm Jul 19 '16 at 13:23
-
You're right. Looks like the site is down. Managed to find the cached version at https://webcache.googleusercontent.com/search?q=cache:OILQTnM_gfIJ:https://java.nicholaswilliams.net/TeamCityPlugins/introduction+&cd=1&hl=en&ct=clnk&gl=uk – John Jul 19 '16 at 15:03
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.

- 2,429
- 4
- 24
- 34
How to set parameter
Step 1: Using IDE to pick up which one you want to use
Step 2: %dep.[B id].build.number% from another project name
echo %CAPR_number% <-- Parameter Name

- 7,679
- 13
- 55
- 68