TeamCity SVN提交信息

5
我正在使用TeamCity和Octopus Deploy进行自动化部署。每次构建都是由对SVN存储库的提交触发的。
我想使用提交消息,例如“对布局页面进行了一些小更改”,作为我创建的Octopus Deploy发布的发布说明。有人知道我可以在TeamCity中使用哪个变量来填充这个吗?
我已经使用了几个参数(如vcsroot.name.url、vcsroot.url),以及vcsroot.labelingMessage,但只会粘贴默认消息。
这可能吗?将更改的详细信息通知给业务测试用户的电子邮件会很好。然后,我可以让开发人员更详细地描述他们所提交的内容。
3个回答

4

在TeamCity中没有包含提交信息的参数。您可以使用存储在build.vcs.number.<VCS root ID>中的修订号,在构建脚本中获取提交信息。例如,像这样:svn log -r <revision_number> --username <user> --password <password> <url>


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

0

目前我不确定准确的 API 调用(这里的文档应该会帮到你),但是你可以通过在之前的构建步骤中使用 curl/powershell 调用 TeamCity REST API,并获取 TeamCity 检测到的当前构建的版本控制系统(VCS)变更信息的详细信息,通过 服务消息 动态地将其添加到 TeamCity 参数中。这与你的 VCS 无关,这可能是一件好事。

然后,你可以通过 Octo.exe 发送此参数来填充你的发布说明。

我会尽快更新一个 API 调用示例...

或者,你也可以看一下这个(自插一波):https://github.com/BenPhegan/TeamCityBuildChanges


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接