5

我正在使用 TeamCity 和 Octopus Deploy 的自动部署。每个构建都由对 SVN 存储库的提交触发。

我想使用提交消息,例如“对布局页面进行一些小的更改”,以用作我创建的 Octopus Deploy 版本的发行说明。有谁知道我可以在 TeamCity 中使用哪个变量来填充它?

我已经使用了几个参数(vcsroot.name.url、vcsroot.url 建议在另一个问题上)以及 vcsroot.labelingMessage 但这只是保留在默认消息中。

这可能吗?最好向业务测试用户发送一封电子邮件,告知他们发生了什么变化。然后我可以让开发人员更详细地描述他们所做的事情。

4

3 回答 3

4

TeamCity 中没有包含提交消息的参数。您可以使用存储在build.vcs.number.<VCS root ID>. 例如像这样svn log -r <revision_number> --username <user> --password <password> <url>

于 2014-07-29T11:22:59.763 回答
1

我今天写了一个 powershell 脚本,它为git. 我相当肯定它可以以最小的努力适应 SVN。

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
于 2015-01-30T23:23:12.427 回答
0

我现在不确定确切的 API 调用(这里的 doco应该可以帮助您),但是您可以从之前的构建步骤(通过 curl / powershell)调用 TeamCity REST API 并获取 TeamCity 拥有的变更集详细信息从 VCS 中检测到当前正在运行的构建,并通过服务消息将其动态放入 TeamCity 参数中。这与您的 VCS 无关,这可能是件好事。

然后,您可以将此参数发送到 Octo.exe 以填充您的发行说明。

我将尝试使用示例 API 调用进行更新...

或者,您可以看看这个(无耻插件):https ://github.com/BenPhegan/TeamCityBuildChanges

于 2014-07-29T12:35:32.287 回答