Up to now I am using
$(Build.DefinitionName)_1.0.$(Year:yy)$(DayOfYear).$(Rev:r)
as the build number format for all my build definitions.
Now I have the (personal) problem when one build definition runs often per day and another only seldom does, that even if the latter one ran last, it has a lot smaller revision number than the often run build definiton which I don't like a lot.
Now I am wondering if there is some variable which holds the value of the total count of builds that were already run during the day and use that variable in my build number format instead of the revision.
There isn't any out of box variable to count this. You can add a powershell script task in your build definition to count the build of today and update the build number via calling VSTS Rest API. Following is the script to achieve this feature(You need to enable "Allow Scripts to Access OAuth Token" option in your build definition to use this script):
##Generate credential
$user = "any"
$pwd = $env:SYSTEM_ACCESSTOKEN
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$pwd)))
##Count build of today
$today = Get-Date
$collectionuri = $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI
$project = $env:SYSTEM_TEAMPROJECT
$uri = $collectionuri + $project + '/_apis/build/builds?api-version=2.0&minFinishTime=' + $today.ToShortDateString()
$response = Invoke-RestMethod -Method Get -Uri $uri -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType application/json
$buildcount = $response.count
##Update build number
$number = $buildcount + 1
$buildnumber = 'xxx.xxx.xxx.' + $number
Write-Host "##vso[build.updatebuildnumber]$buildnumber"