Skip to content

Instantly share code, notes, and snippets.

@ediblecode
Created August 23, 2017 07:22
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save ediblecode/efcd82a36b9439a1878787b34b203fb8 to your computer and use it in GitHub Desktop.
Save ediblecode/efcd82a36b9439a1878787b34b203fb8 to your computer and use it in GitHub Desktop.
Powershell script to parse a package.json version and use as the build number in TeamCity
$version = (Get-Content package.json) -join "`n" | ConvertFrom-Json | Select -ExpandProperty "version"
$buildCounter = "%build.counter%"
$buildNumber = "$version.$buildCounter"
Write-Host "##teamcity[buildNumber '$buildNumber']"
@dannyrb
Copy link

dannyrb commented May 31, 2018

Beautiful! Thanks for sharing this with a gist! 🥇

@alexkates
Copy link

Very helpful, thanks!

@ediblecode
Copy link
Author

No problem, glad it was useful!

@philharlow
Copy link

Another way I stumbled upon:

$version = node -p "require('./package.json').version"

@ediblecode
Copy link
Author

Oh nice use of -p @philharlow - I hadn't seen this before. For anyone reading this, here are the docs for -p - it evaluates the argument as JavaScript and returns the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment