【问题标题】:How to get the version number of the last successful build?如何获取上次成功构建的版本号?
【发布时间】:2019-01-07 22:53:38
【问题描述】:
【问题讨论】:
标签:
teamcity
continuous-deployment
【解决方案1】:
因此,我决定使用 PowerShell 构建步骤中的 TeamCity REST API 从上次成功构建中检索 %maven.project.version%:
$client = New-Object System.Net.WebClient
$client.Credentials = New-Object System.Net.NetworkCredential $username, $password
$latestBuildUrl = "http://localhost/httpAuth/app/rest/builds/?locator=buildType:Development,count:1,status:SUCCESS"
[xml]$latestBuild = $client.DownloadString($latestBuildUrl)
$latestBuildId = $latestBuild.builds.build.id
$propertiesUrl = "http://localhost/httpAuth/app/rest/builds/id:$latestBuildId/resulting-properties"
[xml]$properties = $client.DownloadString($propertiesUrl)
$mavenProjectVersion = $properties.SelectSingleNode("//property[@name='maven.project.version']").value
【解决方案2】:
我认为你的方法是合理的。
另一种方法是:
- 您的构建将
%maven.project.version% 打印到一个文件中
- 您的构建配置将文件发布为工件
- 你下载类似
/repository/download/BUILD_TYPE_EXT_ID/.lastSuccessful/ARTIFACT_PATH的东西(阅读更多here)
我想它更容易实现但有点混乱(额外的步骤/文件 = 混乱)。
【解决方案3】:
这将适用于 TeamCity Enterprise 2018.1.1:
http://<teamcity_hostname>/httpAuth/app/rest/buildTypes/<your_build_type>/builds/status:success/number
要获取可用的构建类型和其他构建属性,请使用:
http://<teamcity_hostname>/httpAuth/app/rest/builds