2015-11-06 54 views
1

背景如何获取上次成功构建的版本号?

我有用于安装和卸载的假象方法第三方Web服务。在安装和卸载时,都需要指定一个名为package-%maven.project.version%.zip的工件。在安装新软件包之前,我需要卸载以前安装的软件包。

解决方案

我发现这个solution,但因为这是最后一步,实现持续部署,我需要一些自动化的,而不是一个提示。

能够由生成步骤是自动化的另一个解决方案是利用TeamCity的REST API的:

  1. 呼叫http://localhost/httpAuth/app/rest/builds/?locator=buildType:Development,count:1,status:SUCCESS
  2. 使用建立在从步骤1响应ID调用http://localhost/httpAuth/app/rest/builds/id:[build-id]/resulting-properties
  3. 检索值来自步骤2中的响应中的以下节点<property name="maven.project.version" value="1.2.3"/>

问题

是否有比使用TeamCity的REST API更简单的方法?

回答

2

所以,我决定使用TeamCity的REST API从一个PowerShell构建步骤来检索上次成功构建%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%到一个文件
  2. 您的构建配置文件发布为伪影
  3. 你下载类似/repository/download/BUILD_TYPE_EXT_ID/.lastSuccessful/ARTIFACT_PATH(阅读更多here

我想这会更容易实现,但有点杂乱(额外的步骤/文件=混乱)。

相关问题