functions/Expand-VersionFromBranch.ps1

function Expand-VersionFromBranch {
    param(
        [Parameter(Mandatory = $true)]
        [string]$BranchName
    )

    if($BranchName -match 'releases/v?(?<version>\d+\.\d+\.\d+)-?(?<label>\w+)?'){
        [Version]$targetVersion = $Matches.version

        Set-PipelineVariable -Name 'MajorVersion' -Value $targetVersion.Major
        Set-PipelineVariable -Name 'MinorVersion' -Value $targetVersion.Minor
        Set-PipelineVariable -Name 'BugfixVersion' -Value $targetVersion.Build
        Set-PipelineVariable -Name 'VersionLabel' -Value $Matches.label
    }
    else {
        throw 'Could not parse version number from branch name!'
    }
}