package.json versions and teamcity

Viewed 3800

We are using TeamCity for our builds and deployments, and as part of this we are wanting to have TeamCity define the version number in the package.json file. We historically were using gulp-bump which would bump the version number however TeamCity wasn't basing its build number upon the details within the package.json file.

So is there a simple way to get TC to update the package.json with a specific version number? I know I could pass a var to gulp somehow and get it to set the package.json version that way but I was hoping there was a more "automated" way of doing it.

4 Answers

You can easily change this command in the build step section package.json using this command

npm version "1.0.%build.number%" --allow-same-version

--allow-same-version This is for a duplicate version

I just added a command line build step to teamcity with the following:

call npm install -g json
call json -I -f package.json -e "this.version='1.0.%build.number%'"

Which will adjust your patch number to whatever the team city build number is

In TeamCity I found it much easier (after trying various techniques) just to do a find and replace on the package.json using Powershell.

Add a Powershell build step with:

$packageFile = "D:\PathToPackageFile\package.json"
(Get-Content $packageFile).replace('"version": "0.0.0"', '"version": "%build.number%"') 
| Set-Content $packageFile
Related