-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-version.ps1
37 lines (30 loc) · 1.23 KB
/
set-version.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
if(-not $Env:BUILD_SOURCEBRANCHNAME)
{
Write-Error "The $Build.SourceBranchName environment variable must be set"
exit 1
}
if(-not $Env:BUILD_BUILDID)
{
Write-Error "The $Build.BuildId environment variable must be set"
exit 1
}
$MajorMinorFromBranch = $Env:BUILD_SOURCEBRANCHNAME
Write-Host "Major.Minor found from branch name: $MajorMinorFromBranch"
$MostRecentVersion = git describe --tags --abbrev=0
Write-Host "Most recent version from git describe: $MostRecentVersion"
$MostRecentVersionObject = New-Object System.Version($MostRecentVersion)
$MostRecentMajorMinor = $MostRecentVersionObject.Major.ToString() + '.' + $MostRecentVersionObject.Minor.ToString()
$NewVersion
if ($MostRecentMajorMinor -eq $MajorMinorFromBranch)
{
Write-Host "Major.Minor branch version matches most recent tag version, incrementing patch number"
$Patch = $MostRecentVersionObject.Build + 1
$NewVersion = "$MajorMinorFromBranch.$Patch.$Env:BUILD_BUILDID"
}
else
{
Write-Host "Major.Minor branch version does not match most recent tag version, setting patch number as 0"
$NewVersion = "$MajorMinorFromBranch.0.$Env:BUILD_BUILDID"
}
Write-Host "New version set to $NewVersion"
Write-Host "##vso[task.setvariable variable=Version]$NewVersion"