我想使用提交消息,例如“对布局页面进行一些小的更改”作为我创建的 Octopus Deploy 版本的发行说明。有谁知道我可以在 TeamCity 中使用哪个变量来填充它?
我使用了几个参数(vcsroot.name.url、vcsroot.url,如另一个问题上建议的那样)以及 vcsroot.labelingMessage,但这只是保留在默认消息中。
这可能吗?如果能够向业务测试用户发送一封电子邮件,告知他们具体发生了什么变化,那就太好了。然后我可以让开发人员更详细地描述他们所承诺的内容。
build.vcs.number.<VCS root ID>
中的修订号在构建脚本中获取提交消息。例如这样
svn log -r <revision_number> --username <user> --password <password> <url>
.
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
doco 这里应该对您有帮助),但您可以从先前的构建步骤(通过curl / powershell)调用 TeamCity REST API 并获取变更集详细信息TeamCity 已从 VCS 检测到当前正在运行的构建,并通过 service message 将其动态放入 TeamCity 参数中。这与您的 VCS 无关,这可能是一件好事。
然后您可以将此参数发送到 Octo.exe 以填充您的发行说明。我将尝试尽快更新示例 API 调用...
或者,你可以看看这个(无耻插件):
首先,您必须获取构建 ID 并使用该 ID 调用构建端点。您可以在浏览器中将其视为 GET 调用。
http://teamcity:8111/app/rest/builds/id:27302
<changes>
节点。这包括更改列表中的
href="/app/rest/changes?locator=build:(id:27302)"
。
<changes count="4" href="/app/rest/changes?locator=build:(id:27302)"/>
但正如您所看到的,您可以使用构建 id 来完成此操作,但您可能需要构建 url 中的其他详细信息。现在你这样称呼。
teamcity:8111/app/rest/changes?locator=build:(id:27302)
更改ID的列表以及这些更改ID的URL。
href="/app/rest/changes/id:71802"