How to reset VSTS counter?

Viewed 2157

We have a need to reset VSTS counter. I do not see any way to do this through UI. There is a way to do it by directly invoking reset build counter REST API, but in order to do this, you need to know the counter id, which you should be able to find out by invoking get a definition REST API. Unfortunately, no matter what I do get a definition call does not return build definition counter.

What am I missing?

2 Answers

Scott Dallamura from Microsoft wrote this thread:

the counters feature was experimental and removed back in March of this year. I'm not sure how it even got into the documentation, but I'll make sure it gets cleaned up.

I also didn't success to get the counterId in an API call.

At workaround, you can reset the revision of the build number if you change the build definition name, you can just add/remove a character.

Instead of trying to reset the counter variable, you could create a new variable with a GUID prefix.

This solution creates duplicate counters which might not be ideal but this gives you the ability to revert back to the previous counter values, if necessary.

Please see the following YAML code snippet

variables: 
  ...
  #Change this Guid if you require a reset seed on the same value.
  resetCounterGuid: 'efa9f3f5-57fb-4254-8a7a-06d5bb365173'
  buildrevision: $[counter(format('{0}\\{1}',variables['resetCounterGuid'],variables['YOUR_DEFINED_VARIABLE']),0)]
 ...
Related