Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to permanently update the value of a TeamCity build parameter as a result of a custom run?

Tags:

teamcity

Is it possible to permanently update the value of a build parameter as a result of a custom run?

For example, consider a build which is configured to have the build number format: %Major%.%Minor%.%Patch%.%build.counter%

Major, Minor and Patch and defined in the build configuration to have certain values. For the sake of an example, lets say this gives a build number of 3.1.2.36.

It is possible to change the build number by clicking '...' next to run and then changing the value of one of the params. Changing Minor from 1->2 and patch from 2->0 would give the next build the number 3.2.0.37.

I'm not overly concerned that 37 hasn't be reset to 0, but the problem is that the next build which is triggered (not as a result of a custom run) will have the build number 3.1.2.38 which is a lower number. Is it possible that when you run a custom build and change the numbers that the new values are persisted?

I am looking for a way that users with no TeamCity admin rights can cause the version number to be incremented according to the changes they have made.

We are running v8.1.2 (build 29993).

like image 251
infojolt Avatar asked Apr 28 '14 10:04

infojolt


People also ask

How do I change my TeamCity build number?

Go to the General Settings of the build configuration. Click the orange Show advanced options. Set the Build counter to your desired value. Set the Build number format to %build.

How do I use custom build in TeamCity?

To run a custom build with specific changes, open the build results page, go to the Changes tab, expand the required change, click the Run build with this change, and proceed with the options in the Run Custom Build dialog. Use HTTP request or REST API request to TeamCity to trigger a build.


1 Answers

To fix the issue I used the TeamCity REST API. I created a new build param of type prompt called 'ReleaseType' which can be either Patch, Minor or Major. This is then used in this command line script which is set up as a TeamCity build step:

IF "%ReleaseType%"=="Major" (
set /a newVersion=%VersionMajor%+1
curl -v --request PUT -d 0 --Header "Content-Type: text/plain" http://username:password@servername:8080/httpAuth/app/rest/projects/%system.teamcity.projectName%/parameters/VersionMinor
curl -v --request PUT -d 0 --Header "Content-Type: text/plain" http://username:password@servername:8080/httpAuth/app/rest/projects/%system.teamcity.projectName%/parameters/VersionPatch
)

IF "%ReleaseType%"=="Minor" (
set /a newVersion=%VersionMinor%+1
curl -v --request PUT -d 0 --Header "Content-Type: text/plain" http://username:password@servername:8080/httpAuth/app/rest/projects/%system.teamcity.projectName%/parameters/VersionPatch
)

IF "%ReleaseType%"=="Patch" (
set /a newVersion=%VersionPatch%+1
)

curl -v --request PUT -d %%newVersion%% --Header "Content-Type: text/plain" http://username:password@servername:8080/httpAuth/app/rest/projects/%system.teamcity.projectName%/parameters/Version%ReleaseType%
curl -v --request PUT -d 0 --Header "Content-Type: text/plain" http://username:password@servername:8080/httpAuth/app/rest/buildTypes/id:%dep.Dependant_BuildName.system.teamcity.buildType.id%/settings/buildNumberCounter

This increments the specified build number and resets downstream version parts to 0.

For example, a minor version increase on 3.2.12.122 goes to 3.3.0.0.

Note - in my particular example above the build counter is reset on a dependant build and not the configuration which is running. This may or may not be what you are after. Replace

%dep.Dependant_BuildName.system.teamcity.buildType.id%

with

%system.teamcity.buildType.id%

if you want to reset the current running build configuration.

like image 176
infojolt Avatar answered Sep 19 '22 16:09

infojolt