1

Background

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.

Solutions

I found this solution, but as this is the final step to achieve continuous deployment, I need something automated and not a prompt.

Another solution that can be automated by a build step is to make use of the TeamCity REST API:

  1. Call http://localhost/httpAuth/app/rest/builds/?locator=buildType:Development,count:1,status:SUCCESS
  2. Use build id in response from step 1 to call http://localhost/httpAuth/app/rest/builds/id:[build-id]/resulting-properties
  3. Retrieve value from the following node in the response from step 2, <property name="maven.project.version" value="1.2.3"/>.

Question

Is there a simpler way than using the TeamCity REST API?

Community
  • 1
  • 1
Martin4ndersen
  • 2,806
  • 1
  • 23
  • 32

3 Answers3

3

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
Martin4ndersen
  • 2,806
  • 1
  • 23
  • 32
1

I think your approach is sound.

Another approach would be:

  1. your build prints %maven.project.version% into a file
  2. your build config publishes the file as an artifact
  3. you download something like /repository/download/BUILD_TYPE_EXT_ID/.lastSuccessful/ARTIFACT_PATH (read more here)

I guess it's a little easier to implement but a bit more messy (extra steps/files = clutter).

sferencik
  • 3,144
  • 1
  • 24
  • 36
1

This will work on TeamCity Enterprise 2018.1.1: http://<teamcity_hostname>/httpAuth/app/rest/buildTypes/<your_build_type>/builds/status:success/number

To get your available build types and other build attributes use: http://<teamcity_hostname>/httpAuth/app/rest/builds

Naor Bar
  • 1,991
  • 20
  • 17