How to reset build counter via REST API Follow
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!
Please sign in to leave a comment.
Hello,
I believe that this:
http://www.haveyougotwoods.ca/2012/06/18/local-build-usingincrementing-team-city-version-number
Has some information that will help you.
Gary
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"
Do you want to change the build counter in a PowerShell build step? If so, then this also works by https://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingBuildNumber.
Not a problem at all, glad to hear that you got it figured out!
Gary
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
Hi,
You can also find some examples at the end of Build Configuration and Template Settings section.