Custom build number for .NET project


I am quite new to TC and after setting up the first projects I hit on a problem I can't find a simple solution for, although the requirement don't seem too odd to me.

Here goes: I set up a TC project + configuration to build a .NET project. This project contains a file (SolutionInfo.cs) that holds a version number, which is written to various artefacts during the build process. This version number has the format M.m.b.r (or I need to to update this version number automatically befoer the build starts and use it as TCs internal build number as well to identify the build.

To do so I wrote a serverside plugin that:

  1. Reads major/minor parts of the version number from SolutionInfo.cs
  2. Gets the current TC build counter via SRunningBuild.getBuildType().getBuildNumbers().getBuildCounter()
  3. Combines 1 and 2 and sets the build number

That's fine so far, but the revision number (which is the same as the changeset number) is still missing. Where can I get that from? I browsed the API documentation, but didn't find a way to obtain it, though it can be accesses in the UI via the {build.vcs.number.MyVCSRoot} placeholder.

Next point: On agentside I need to write this newly constructed number back to the SolutionInfo.cs file. I wrote another (agentside) plugin to do so. But how does the agent access the build number maintained by the server? There is a lot of information to be obtained from the AgentBuildInfo interface, but not the build number, as far as I can see.

Now, all this seems quite complicated to me. On the other hand, the task of writing some build information to files/artefacts doesn't seem to unusual. Is there any other way to achive this? Did I miss something?

Ideas are welcome. Thanks - Jan.

BTW: Is there a way to search this board for keywords?

Comment actions Permalink


Here is a related thread:

A good way to set a custom build number is to provide a new variable that can be used in the build number pattern. This is already possible via open API since the latest 4.1 EAP. All parameters added via an extension point "jetbrains.buildServer.serverSide.parameters.BuildParameterReferencesProvider" will be accessible with "" syntax in the build number. You can then push your major/minor varions as proparties, use them in the build number pattern and then use the build number in the build script (or in agent-side plugin) to patch SolutionInfo.cs.

As to your questions:
You can get VCS recisions via SBuild.getBuildPromotion.getRevisions()
The build number can be obtained on agent from the build parameters: AgentRunningBuild.getBuildParameters().getSystemProperties().get("build.number");
Please note that the buld number can be modified during the build stages if it has references to patterns or is modified inside the build script.

> BTW: Is there a way to search this board for keywords?

The search field is in the top-right corner of the page. Is it what you were looking for?

Best regards,

Yegor Yarko
Project Manager (TeamCity)
JetBrains, Inc
"Develop with pleasure!"

Comment actions Permalink

Hi Yegor,

thank you for the hints. EAP is not an option since we need a reliable CI environment (we're running TC 4.0.1). But that's no problem. I followed the example given here: So, the plugin checks for a special token in the build number format and -if present- creates a new build number, which is used to identify the build and is propagated to the build agent as well via system property.

Unfortunately there's one last hitch: You suggested to use SBuild.getBuildPromotion.getRevisions() to get the revision number, but this list is continually empty, at least in the context of BuildServerAdapter. Is there another way to get the number of the revision that is about to be built?

And yes: That is the search box I was looking for.

Regrads - Jan.

Comment actions Permalink

getRevisions() may return empty collection if changes are not yet checked for a build. There is special event BuildServerListener::changesLoaded() which is sent when changes are collected and stored in the build but the build itself is not yet sent to an agent.

Comment actions Permalink

Hm. Then how do I obtain the revision number (or changeset number) from inside a server-side plugin? There may be no changes in the repository, but there certainly is a current revision number. After all TC does this. I just want to do in a plugin what's done in Configuration|General Settings via the {build.vcs.number} placeholder.

Thanks & regards - Jan.

Comment actions Permalink

If changes were not detected getRevisions() still will return non empty collection. I.e. it will return latest revisions.

Comment actions Permalink

Ok, got it. The collection contains exactly one item per vcs root defined, correct?

Regards - Jan.

Comment actions Permalink

Pavel, thanks for your support. - Jan.


Please sign in to leave a comment.