I'm trying to customise the build numbers that each pipeline run gets with a counter and then formatting to 4 characters (leading zeros), ideally as hex as well but can work with just decimal.
I've tried the suggested:
name: $[format('{0:D4}', counter(0))]
but get the error An error occurred while loading the YAML build pipeline. The format specifiers 'D4' are not valid for objects of type 'Number'
but this is the general form that I've been able to find examples of.
Shamrai's answer works fine but keep in mind that it will modify the initial build number somewhere after the pipeline starts.
You can also try the following using special variable $(Rev)
(see Run number):
$(Rev:rrrr)
But the first revision might not be 0001
if you already ran the pipeline before:
$(Rev:r)
resets to 1
when any other part of the build number changes:
name: $(Date:yyMMdd)-$(Rev:rrrr)
So in the case above the revision will reset every day.
Going back to your original problem, and if you need to start from 0001
the following workaround won't work - it's basically the same as using $(Rev:rrrr)
if you have less than 1000 revisions:
name: 0$(Rev:rrr)
But changing the prefix to 1
resets the build number:
name: 1$(Rev:rrr)