【问题标题】:How to get the version number of the last successful build?如何获取上次成功构建的版本号?
【发布时间】:2019-01-07 22:53:38
【问题描述】:

背景

我有一个第三方 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. 使用构建 ID 响应步骤 1 调用 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 更简单的方法?

【问题讨论】:

    标签: 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】:

      我认为你的方法是合理的。

      另一种方法是:

      1. 您的构建将%maven.project.version% 打印到一个文件中
      2. 您的构建配置将文件发布为工件
      3. 你下载类似/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

        【讨论】:

          猜你喜欢
          • 2015-08-08
          • 1970-01-01
          • 1970-01-01
          • 2019-05-09
          • 1970-01-01
          • 2011-11-21
          • 2022-01-02
          • 2020-06-24
          • 2011-09-29
          相关资源
          最近更新 更多