如何获取上次成功构建的版本号? [英] How to get the version number of the last successful build?
问题描述
背景
我有一个第三方Web服务,其中包含用于安装和卸载工件的方法。在安装和卸载时,都指定了一个名为package-%maven.project.version%.zip的工件。在安装新软件包之前,我需要卸载以前安装的软件包。
I have a third-party web service with methods for installing and uninstalling an artifact. Both when installing and uninstalling, you specify an artifact named package-%maven.project.version%.zip. Before installing a new package, I need to uninstall the previously installed package.
解决方案
我发现了这个解决方案,但这是实现连续部署的最后一步,因此我需要一些东西
I found this solution, but as this is the final step to achieve continuous deployment, I need something automated and not a prompt.
另一个可以通过构建步骤自动化的解决方案是利用TeamCity REST API:
Another solution that can be automated by a build step is to make use of the TeamCity REST API:
- 调用 http:// localhost / httpAuth / app / rest / builds /?locator = buildType:Development,count:1,status:SUCCESS
- 使用内部版本步骤1的响应ID来调用 http://本地主机/ httpAuth / app / rest / builds / id:[build-id] / resulting-properties
- 从fol检索值在步骤2的响应中降低节点,
<属性名称= maven.project.version value = 1.2.3 />
。
- Call http://localhost/httpAuth/app/rest/builds/?locator=buildType:Development,count:1,status:SUCCESS
- Use build id in response from step 1 to call http://localhost/httpAuth/app/rest/builds/id:[build-id]/resulting-properties
- Retrieve value from the following node in the response from step 2,
<property name="maven.project.version" value="1.2.3"/>
.
问题
有没有比使用TeamCity更简单的方法REST API?
Is there a simpler way than using the TeamCity REST API?
推荐答案
因此,我决定从PowerShell构建步骤中使用TeamCity REST API来检索%maven.project.version%
来自最近一次成功的构建:
So, I decided on using the TeamCity REST API from a PowerShell build step to retrieve %maven.project.version%
from the last successful build:
$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
这篇关于如何获取上次成功构建的版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!