With this update your YAML is valid:
    ${{ if endsWith( variables['Build.SourceBranchName'], '/master' ) }}: 
      buildVersion: variables['mavenVersion']
    ${{ else }}: 
      buildVersion: variables['Build.SourceBranchName']
All works fine with this
trigger: none
name: if-else
pool:
  vmImage: ubuntu-latest
variables:
  ${{ if endsWith( variables['Build.SourceBranchName'], 'master' ) }}: 
    buildVersion: 'master'
  ${{ else }}: 
    buildVersion: 'none-master'
steps:
- script: |
    echo "$(Build.SourceBranchName)"
    echo "$(buildVersion)"
  displayName: 'Display buildVersion'
Simply Build.SourceBranchName contains just master.
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/1121efc8-6445-4e19-be5a-8d525a76467e.sh
master
master
Finishing: Display buildVersion
Note: This doesn't work on Azure DevOps Server - please be aware of that! Thanks @psulek for highlighting this!