Created
March 15, 2017 21:30
-
-
Save a5ync/b2a45ac723243f315568e824de149c4c to your computer and use it in GitHub Desktop.
TeamCity: Inject github short hash to project.json files of aspnet core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rootDirectory="%teamcity.build.workingDir%" | |
$gitHash="%build.vcs.number%" | |
echo "githash is $gitHash" | |
$gitShortHash=$gitHash.Substring(0,7) | |
$listOfFiles = @( | |
"$rootDirectory\src\TestProject\project.json" | |
) | |
foreach($file in $listOfFiles) | |
{ | |
$a = Get-Content $file -raw | ConvertFrom-Json | |
$currentVersion = $($a.version) | |
#clean up previous github hash | |
$currentVersion = $currentVersion -split '-',2 |select-object -first 1 | |
echo "The current value of $file is $currentVersion" | |
$newVersion="$currentVersion-$gitShortHash" | |
echo "The new value of version for $file is $newVersion" | |
$a.version=$newVersion | |
#regenerate the file with modified node | |
$a|ConvertTo-Json -Depth 20|Set-Content $file | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment