How to reset build counter via REST API

Hello,

I'm interseted to learn how to reset build counter through REST API. I looked for it but haven't been able to find a solution. Any help will be much appreciated.

Thanks!

6 comments
Comment actions Permalink

Thank you so much for pointing me to the right direction. I was able to successfully come up with a solution to reset the build counter using PowerShell. Here is the code. I hope this will help someone out there as well.

$buildCounterUri = "http://teamcityServer/httpAuth/app/rest/buildTypes/[BuildTypeId]/settings/buildNumberCounter"
$TeamCityPassword = "YourPass"
$TeamCityUsername = "YourUsername"

$secpasswd = ConvertTo-SecureString $TeamCityPassword -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($TeamCityUsername, $secpasswd)
$result = (Invoke-RestMethod -Method Put -Credential $cred -Uri $buildCounterUri -ContentType "text/xml" -Body 0)


Write-Host "Done"


0
Comment actions Permalink

Not a problem at all, glad to hear that you got it figured out!

Gary

0
Comment actions Permalink

Hello mar99,

I believe that the question was how to reset the build counter, not set the build number.  Although the build counter normally forms part of the build number, i.e. build_number = 1.0.%build_counter%, setting the build number through a TeamCity service message doesn't have the effect of overriding the build counter, only the build number for the current build.

The solution that Hayato has come up with seems like it should do the trick though.

Gary

0
Comment actions Permalink

Hi,

You can also find some examples at the end of Build Configuration and Template Settings section.

0

Please sign in to leave a comment.