Search code examples
teamcityoctopus-deploy

How to append git short hash into Octopus release from TeamCity


Using an OctopusDeploy: Create Release runner in TeamCity, I can create a release with the build.number fairly easily.

I'd like to add a suffix of the git commit short hash.


Solution

  • Here is how I solved it - scraped from various internet sources

    In my CI Build, I added

    1. A parameter named system.GitHashShort
    2. Created a Powershell runner which executes this

      $hash = "%build.vcs.number%" $shortHash = $hash.substring(0,7) Write-Host "##teamcity[setParameter name='system.GitHashShort' value='$shortHash']"

    In my Deploy build configuration which is a snapshot dependency on CI Build

    1. For the OctopusDeploy: Create Release runner, set the release number to be

      %build.number%-%dep.MyAwesomeApp.system.GitHashShort%

    This then gives builds of a format like 8.3.422.34-deadbee