在TeamCity中创建更改日志工件

gre*_*ade 15 teamcity continuous-integration changelog

有没有一种简单的方法让TeamCity包含一个text或html change-log作为其输出工件之一?

也许我需要沿着让msbuild或其他进程创建更改日志的路线,但是当TeamCity为每个构建生成一个时,我想知道是否已经有一种简单的方法来将其作为工件访问并将其包含在工件路径指令,以便它可以作为发布包的一部分.

pet*_*ven 12

是的,更改日志可作为文件访问,此文件的路径位于TeamCity构建参数中:

%system.teamcity.build.changedFiles.file%
Run Code Online (Sandbox Code Playgroud)

所以你可以这样做:

  • 在构建中添加命令行构建步骤.
  • 使用类型自定义脚本.
  • 输入此脚本:
copy "%system.teamcity.build.changedFiles.file%" changelog.txt
Run Code Online (Sandbox Code Playgroud)
  • 最后编辑构建的工件规则,以在工件中包含changelog.txt(常规设置 - >工件路径 - >添加"changelog.txt").


Dan*_*ose 12

您可以通过TeamCity的REST API生成更改日志.可以在此处找到PowerShell脚本:

<#
.SYNOPSIS
    Generates a project change log file.
.LINK
    Script posted over:
    http://open.bekk.no/generating-a-project-change-log-with-teamcity-and-powershell
    Also See https://stackoverflow.com/questions/4317409/create-changelog-artifact-in-teamcity

#>

# Where the changelog file will be created
$outputFile = "%system.teamcity.build.tempDir%\releasenotesfile_%teamcity.build.id%.txt"
# the url of teamcity server
$teamcityUrl = "%teamcity.serverUrl%"
# username/password to access Teamcity REST API
$authToken=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("%system.teamcity.auth.userId%:%system.teamcity.auth.password%"))
# Build id for the release notes
$buildId = %teamcity.build.id%

# Get the commit messages for the specified change id
# Ignore messages containing #ignore
# Ignore empty lines
Function GetCommitMessages($changeid)
{
    $request = [System.Net.WebRequest]::Create("$teamcityUrl/httpAuth/app/rest/changes/id:$changeid")     
    $request.Headers.Add("AUTHORIZATION", "Basic $authToken");
    $xml = [xml](new-object System.IO.StreamReader $request.GetResponse().GetResponseStream()).ReadToEnd()    
    Microsoft.PowerShell.Utility\Select-Xml $xml -XPath "/change" |
        where { ($_.Node["comment"].InnerText.Length -ne 0) -and (-Not $_.Node["comment"].InnerText.Contains('#ignore'))} |
        foreach {"+ $($_.Node["user"].name) : $($_.Node["comment"].InnerText.Trim().Replace("`n"," "))`n"}
}

# Grab all the changes
$request = [System.Net.WebRequest]::Create("$teamcityUrl/httpAuth/app/rest/changes?build=id:$($buildId)")
$request.Headers.Add("AUTHORIZATION", "Basic $authToken");
$xml = [xml](new-object System.IO.StreamReader $request.GetResponse().GetResponseStream()).ReadToEnd()

# Then get all commit messages for each of them
$changelog = Microsoft.PowerShell.Utility\Select-Xml $xml -XPath "/changes/change" | Foreach {GetCommitMessages($_.Node.id)}
$changelog > $outputFile
Write-Host "Changelog saved to ${outputFile}:"
$changelog
Run Code Online (Sandbox Code Playgroud)

  • 在TeamCity 10.x中使用上述脚本的任何人都希望将AUTHORIZATION的Headers更新为"Basic $ authToken". (5认同)