0

I'm changing the build number of the TeamCity (9.1.4) build with service messages (Build Script Interaction) like this in Powershell:

Write-Host "##teamcity[buildNumber '$version.$arg2']"

This is working absolutely fine.

The problem is that the AssemblyInfoPatcher doesn't want to use this updated build number.

So I tried to use a variable/parameter for it but this also doesn't work.

I defined the following variable "Major.Minor.Patch" as a "Configuration Parameter" or as an "Environment Variables". The AssemblyInfoPatcher is using these variables just fine and changes the file version of my files with the version defined in TeamCity in the build.

If I try to change the variable/parameter with a service message it doesn't work. The AssemblyInfoPatcher is still using the old value.

Example with environment variable

Write-Host "##teamcity[setParameter name='env.Major.Minor.Patch' value='$version']"

Example with configuration parameter

Write-Host "##teamcity[setParameter name='Major.Minor.Patch' value='$version']"

Am I doing something wrong or is it just not possible? The only thing I want is that my files have the same version number as my TeamCity build...

Shamshiel
  • 2,051
  • 3
  • 31
  • 50

1 Answers1

2

The AsssemblyInfoPatcher runs before any of the build steps (and then runs again to revert your AssemblyInfo files after all your build steps). Thus, if one of your build steps sets Major.Minor.Patch using a service message, it's really too late to the game.

Maybe you could string multiple build configs together. The first config (A) would set up the parameter like you're doing now, and then trigger the second config (B), which would use the AssemblyInfoPatcher. B would have a snapshot dependency on A (in addition to the finish-build trigger) and thus its AssemblyInfoPatcher would be able to refer to %dep.A.Major.Minor.Patch%. This parameter, of course, would already be available when B's AssemblyInfoPatcher runs.

sferencik
  • 3,144
  • 1
  • 24
  • 36
  • Thank you for your quick response. Do you maybe have a link to a tutorial on how to string builds together? I have never done that in TeamCity. – Shamshiel Apr 13 '16 at 04:52
  • 1
    1) Create a new buildconfig called SetVersion, with a build step that will do the service message. 2) Modify your original build config's trigger, adding a "Finish build trigger" on SetVersion. 3) Modify your original build config's dependencies, adding a "Snaphot dependency" on SetVersion. 4) Modfy your current build config's AssemblyInfoPatcher to refer to `%dep.SetVersion.Major.Minor.Patch%`. I hope that helps. – sferencik Apr 13 '16 at 06:40
  • 1
    Thank you for the brief explanation. I managed to do it myself. I almost did everything exactly like you said but I didn't do step 2. I kept the VCS trigger and it is still working because of the dependency TeamCity builds the Version build first. – Shamshiel Apr 13 '16 at 06:49