Austin Agile DevOps

DevOps in the Cloud
posts - 70 , comments - 7 , trackbacks - 0

TeamCity Build Number from Most Recent Git Tag + 1 Dash Short Sha

We want a semantic version build number derived from the most recent git tag that follows a three-node semantic version format.  We use GitLab and here’s how we do that in TeamCity.

 

1. Add a Powershell build step as follows:

$lastVerTag = git describe --abbrev=0 --tags --match [0-99][.][0-99][.][0-999]
[string]$majMin = $lastVerTag.Substring(0,$lastVerTag.LastIndexOf('.'))
[int]$incr = $lastVerTag.Substring($lastVerTag.LastIndexOf('.'))
$incr = $incr + 1
$semVer = $majMin + '.' + $incr
$Hash = "%build.vcs.number%"
$ShortHash = $Hash.substring(0,7)
Write-Host "##teamcity[buildNumber '$semVer-$ShortHash']"

2. In the Build Configuration Settings General settings set the Build numbe format field to: %build.number%

 

If the most recent Git tag using a valid three-node semantic version format was 0.0.0, then the build number would be: 0.0.1-fe46b10

Print | posted on Tuesday, February 16, 2016 12:42 PM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: