是否可以通过自定义运行永久更新TeamCity构建参数的值?

时间:2014-04-28 10:47:51

标签: teamcity

是否可以通过自定义运行永久更新构建参数的值?

例如,考虑一个配置为具有内部版本号格式的构建: %主要%。%次要%。%%补丁。%build.counter%

Major,Minor和Patch,在构建配置中定义为具有特定值。为了举个例子,假设这给出了一个3.1.2.36的内部版本号。

可以点击' ...'更改内部版本号。然后运行,然后更改其中一个参数的值。将Minor改为1-> 2,将补丁从2-> 0改为将使下一个版本的编号为3.2.0.37。

我并不过分担心37没有被重置为0,但问题是被触发的下一个构建(不是自定义运行的结果)将具有内部版本号3.1 .2.38这是一个较低的数字。是否有可能在运行自定义构建并更改新值保持的数字时?

我正在寻找一种没有TeamCity管理员权限的用户可以根据他们所做的更改来增加版本号的方法。

我们正在运行v8.1.2(build 29993)。

1 个答案:

答案 0 :(得分:8)

要解决此问题,我使用了TeamCity REST API。我创建了一个名为“ReleaseType”的类型提示符的新构建参数,可以是Patch,Minor或Major。然后在此命令行脚本中使用它,该脚本设置为TeamCity构建步骤:

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

这会增加指定的内部版本号,并将下游版本部件重置为0.

例如,3.2.12.122的次要版本增加到3.3.0.0。

注意 - 在我上面的特定示例中,构建计数器在依赖构建上重置,而不是正在运行的配置。这可能是也可能不是你所追求的。替换

  

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

  

%system.teamcity.buildType.id%

如果要重置当前正在运行的构建配置。