5

I'm using automated deployments with TeamCity and Octopus Deploy. Each build is triggered by a commit to the SVN Repository.

I'd like to use the commit message, eg "Made some small changes to the layout page" to be used as the release notes on the Octopus Deploy release that I create. Does anyone know which variable I can use in TeamCity to populate this?

I've used several parameters (vcsroot.name.url, vcsroot.url as recommended on another question) as well as vcsroot.labelingMessage but that just sticks in a default message.

Is this possible? It would be great to send an email to the business test users that informs them exactly what has changed. I can then get the developers to be more descriptive about what they committed.

Paul
  • 3,072
  • 6
  • 37
  • 58

3 Answers3

4

There is no parameter in TeamCity that contains commit message. You can get commit message inside your build script using revision number stored in build.vcs.number.<VCS root ID>. For example like this svn log -r <revision_number> --username <user> --password <password> <url>.

Alina Mishina
  • 3,320
  • 2
  • 22
  • 31
1

I wrote a powershell script today that does that for git. I'm fairly certain it can be adapted for SVN with minimal effort.

https://gist.github.com/ChaseFlorell/716ffd1e4213ecfc8a8b

# credit for getting me going in the right direction
#    http://blogs.lessthandot.com/index.php/uncategorized/access-git-commits-during-a-teamcity-build-using-powershell/

# these properties should be entered into your configuration parameters section
$project = "%Octopus.Project%"
$deployTo = "%Octopus.DefaultEnvironment%"
$buildVersion = "%BuildVersion%"
$octopusApiKey = "%Octopus.BuildDeployBot.APIKey%"
$octopusServer = "%Octopus.Server.Url%"

# these properties should already be configured for you
$vcsGitUrl = "%vcsroot.url%"
$username = "%system.teamcity.auth.userId%"
$password = "%system.teamcity.auth.password%"
$serverUrl = "%teamcity.serverUrl%"
$buildTypeId = "%system.teamcity.buildType.id%"
$buildId = "%teamcity.build.id%"
$gitPath = "%env.TEAMCITY_GIT_PATH%"
$buildNumber = "%build.vcs.number%"
$checkoutDir = "%system.teamcity.build.checkoutDir%"

function Get-TeamCityLastSuccessfulRun{
    $AuthString = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$username`:$password"))
    $Url = "$serverUrl/app/rest/buildTypes/id:$buildTypeId/builds/status:SUCCESS" 
    $Content = Invoke-WebRequest "$Url" -Headers @{"Authorization" = "Basic $AuthString"} -UseBasicParsing
    return $Content
}

function Get-CommitsFromGitLog([string] $StartCommit, [string] $EndCommit){
    $fs = New-Object -ComObject Scripting.FileSystemObject
    $git = $fs.GetFile("$gitPath").shortPath

    $overviewUrl = "$serverUrl/viewLog.html?buildId=$buildId&buildTypeId=$buildTypeId&tab=buildResultsDiv"
    $commitUrl = "$($vcsGitUrl.TrimEnd('.git'))/commit"

    $Cmd = "$git log --pretty=format:""%s [%h...]($commitUrl/%H)"" $StartCommit...$EndCommit"

    $Result = $(Invoke-Expression "$path $Cmd")
    $nl = [environment]::NewLine
    [string]$str = "#TeamCity Auto Deployment  $nl" + "[click here for build overview]($overviewUrl)  $nl$nl"
    $Result | % {$str += " - $_  $nl"}

    return $str
}

$Run = Get-TeamCityLastSuccessfulRun
$LatestCommitFromRun = (Select-Xml -Content "$Run" -Xpath "/build/revisions/revision/@version").Node.Value
$CommitsSinceLastSuccess = Get-CommitsFromGitLog -StartCommit "$LatestCommitFromRun" -EndCommit "$buildNumber"

$CommitsSinceLastSuccess > "$checkoutDir\CommitLog.txt"
$Cmd = "octo.exe create-release --apiKey=$octopusApiKey --server='$octopusServer' --project=$project --deployto=$deployTo  --enableServiceMessages --progress --waitfordeployment --packageversion=$buildVersion --releaseNotesFile=$checkoutDir\CommitLog.txt"
Invoke-Expression $cmd
Chase Florell
  • 46,378
  • 57
  • 186
  • 376
0

I'm not sure of the exact API call right now (doco here should help you), but you can make a call to the TeamCity REST API from a prior build step (via curl / powershell) and get the Changeset Details that TeamCity has detected from VCS for the currently running build, and drop that dynamically into a TeamCity parameter via a service message. This is agnostic to your VCS, which is probably a good thing.

Then you can send this parameter through to Octo.exe to populate your release notes.

I'll try and update shortly with an example API call...

Alternatively, you can take a look at this (shameless plug) : https://github.com/BenPhegan/TeamCityBuildChanges

SteveChapman
  • 3,051
  • 1
  • 22
  • 37