Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have TeamCity update the build version number in a specified file?

Does anyone know of an easy way to show the build version number in an HTML/JavaScript project that uses AMD?

The version number is generated by TeamCity as part of the build process.

Here is what I mean in more details:

One of my js files (e.g. showVersion.js) has a line like this:

  alert('Build version: __build_ver_placeholder__ ');

Ideally, after TeamCity completes the build, it will plug in the actual version number for the place-holder. And the line above will become:

  alert('Build version: 2.1.0 ');



That way, the user can know the build version number by clicking a button on an HTML page which calls the alert() function.

Any idea will be greatly appreciated. Thanks.

like image 475
user3239076 Avatar asked Feb 07 '14 07:02

user3239076


People also ask

How do you set build configuration in TeamCity?

Go to Administration | Projects and open the required project. Alternatively, open the project using the Projects pop-up menu and click Edit Project Settings. The Project Settings page will open. On the Project Settings page, click Create build configuration under the Build Configurations section.

How do you edit building steps in TeamCity?

In Build Steps, click Auto-detect build steps, and then select the proposed steps you want to add to the current build configuration. You can change their settings afterwards. When scanning the repository, TeamCity progressively searches for project files on the two highest levels of the source tree.


1 Answers

You can simply add PowerShell build step containing the following code:

(Get-Content "showVersion.js") 
| Foreach { $_ -Replace "__build_ver_placeholder__", "%build.number%" } 
| Set-Content "showVersion.js";

%build.number% variable will be replaced by TeamCity during the build

like image 181
Alexander Doroshenko Avatar answered Sep 20 '22 15:09

Alexander Doroshenko