背景
我有第三方Web服务,其中包含安装和卸载工件的方法。在安装和卸载时,都指定名为package-%maven.project.version%.zip的工件。在安装新软件包之前,我需要卸载以前安装的软件包。
解决方案
我发现了这个solution,但由于这是实现持续部署的最后一步,我需要一些自动化而非提示。
可以通过构建步骤自动化的另一个解决方案是使用TeamCity REST API:
<property name="maven.project.version" value="1.2.3"/>
中检索以下节点的值。问题
是否有比使用TeamCity REST API更简单的方法?
答案 0 :(得分:2)
因此,我决定使用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
答案 1 :(得分:1)
我认为你的方法很合理。
另一种方法是:
%maven.project.version%
打印到文件/repository/download/BUILD_TYPE_EXT_ID/.lastSuccessful/ARTIFACT_PATH
(阅读更多here)我想它实现起来有点容易,但有点混乱(额外的步骤/文件=混乱)。
答案 2 :(得分:1)
这将适用于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