Is it possible to permanently update the value of

2019-02-07 16:17发布

问题:

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).

回答1:

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.



标签: teamcity