How to generate a build number and share it across projects?

I'm evaluating TeamCity and I like what I see so far, but I've hit a sticking point. Our build number is of the form major.minor.build.revision, and we need to automatically bump the build part when any of a certain set of files changes in our repository. Our existing custom script just asks Perforce if any of those files have changed, and then changes a text file containing the current build number, by bumping the build part of the number by one. This happens at the beginning of the build, and all components of the build inspect this file to find out what the build number is. The file, if it was changed, is then checked into perforce at the end of the build, and we wait for the next build.

In TC I can create a project (call it P1) that has a Perforce clientspec that specifies the list of these 'special'  files that we want to watch for the purposes of bumping the build part of the version number, so that when P1 builds it chages the version file as described above. However, another project (say P2) can't read this updated file, since if P2 shares the same checkout directory as the P1 project, the file gets wiped and pulled again from the repository.

I tried to define an agent-specific environment variable that I could set in project P1 and read in the other projects, but the env. variable doesn't seem to propagate between projects.

Is there something I'm missing here? Is there a simple way to share a generated build number across all projects, or to have one project modify a file pulled out of the repository and have other projects see those changes (without speculatively checking in the file)?

1 comment
Comment actions Permalink

Probably the simplest way it to create a file which will contain build number and publish it as TeamCity artifact. Other builds then can download this artifact and take the same build number. For this to work you will need to change build number right from the build script, this is possible with help of service messages: http://www.jetbrains.net/confluence/display/TCD4/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingBuildNumber

0

Please sign in to leave a comment.