I was closer than I thought. This is not pretty, but it worked. (with more yaml context)
variables:
${{ if eq( variables['Build.SourceBranchName'], 'master' ) }}:
buildVersion: ${{ variables['mavenVersion'] }}
${{ if ne( variables['Build.SourceBranchName'], 'master' ) }}:
buildVersion: ${{ variables['Build.SourceBranchName'] }}
buildKey: ${{ format('{0}_{1}', variables['supportReleaseNumber'], variables['buildVersion']) }}
buildNum: $[counter(variables['buildKey'], 1)] # same as $(Rev:r), but more widely usable
name: $(buildKey)_$(buildNum) # build run name
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…