I was able to get this to work doing an Anti-Pattern for just one part of release flow. But this is not a big deal if you use Azure DevOps because Microsoft provides a quick and easy way to see if your release branch is ahead/behind the master branch. I have tested this and I am using Release Flow for almost complete automation of versioning besides creating a release branch, and new tag at the end of each sprint. This method also is working well for Semantic Versioning 2.0 of my Nuget Packages, which I use views instead of the suffix tags.
Modified Release Flow
I apologize, and hope it is not too late to help someone out. I have added the yml, and I also have a powershell that I made to handle the release branch naming when cherry picking a HF from master. Note that this powershell step adds a version tag on a release branch so that GitVersion will pick it up.
Powershell:
Release {{TeamProject}}/{{RepoName}} with your team project and repo name
- powershell: |
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/definitions/$($env:SYSTEM_DEFINITIONID)?api-version=2.0"
Write-Host "URL:" $url
$definition = Invoke-RestMethod -Uri $url -Headers @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
Write-Host "Pipeline = $($definition | ConvertTo-Json -Depth 100)"
displayName: Build Details
env:
SYSTEM_ACCESSTOKEN: $(system.accesstoken)
- powershell: |
#Get branch version and increment from release branch
$branchName = "$env:BUILD_SOURCEBRANCHNAME"
$versionNotIncremented = ($branchName -Split "-")[1]
[System.Version] $version = "0.0"
[System.Version]::TryParse($versionNotIncremented, [ref]$version) > Null
$ver = New-Object System.Version($version.Major,($version.Minor + 1))
#Create new commit and tag on master
git checkout master
$env:GIT_TRACE=1
git pull
git commit --allow-empty -m "Create Tag ***NO_CI***"
git push https://$env:SYSTEM_ACCESSTOKEN@dev.azure.com/{{TeamProject}}/{{RepoName}}/_git/{{TeamProject}}.Lookup.Api
$commitId = git log --format="%h" -n 1
#$commitId = git rev-parse --short HEAD
git tag $ver $commitId -f -m "Release-$ver"
git push https://$env:SYSTEM_ACCESSTOKEN@dev.azure.com/{{TeamProject}}/{{RepoName}}/_git/{{TeamProject}}.Lookup.Api $ver -f --porcelain
displayName: 'Update Version for Upcoming Release'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/heads/releases/'))
env:
SYSTEM_ACCESSTOKEN: $(system.accesstoken)
GitVersion Yaml:
assembly-informational-format: '{FullSemVer}'
mode: Mainline
branches:
master:
tag: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: master|releases?[/-]
tracks-release-branches: false
is-release-branch: false
feature:
mode: ContinuousDelivery
tag: useBranchName
increment: Inherit
prevent-increment-of-merged-branch-version: false
track-merge-target: false
regex: features?[/-]
tracks-release-branches: false
is-release-branch: false
pull-request:
mode: ContinuousDelivery
tag: PullRequest
increment: None
prevent-increment-of-merged-branch-version: false
tag-number-pattern: '[/-](?<number>\d+)[-/]'
track-merge-target: false
regex: (pull|pull\-requests|pr|[0-9]+)[/-]
tracks-release-branches: false
is-release-branch: false
hotfix:
mode: ContinuousDelivery
tag: beta
increment: Patch
prevent-increment-of-merged-branch-version: false
track-merge-target: false
regex: hotfix(es)?[/-]
tracks-release-branches: false
is-release-branch: false
develop:
mode: ContinuousDeployment
tag: unstable
increment: Patch
prevent-increment-of-merged-branch-version: false
track-merge-target: true
regex: dev(elop)?(ment)?$
tracks-release-branches: true
is-release-branch: false
ignore:
sha: []