Continuous integration 在TeamCity中创建变更日志工件

Continuous integration 在TeamCity中创建变更日志工件,continuous-integration,teamcity,changelog,Continuous Integration,Teamcity,Changelog,有没有一种简单的方法让TeamCity将文本或html更改日志作为其输出工件之一 也许我需要让msbuild或其他流程创建更改日志,但由于TeamCity会为每个生成生成一个更改日志,我想知道是否已经有一种简单的方法可以将其作为工件访问,并将其包含在工件路径指令中,以便它可以成为发布包的一部分。可能您应该使用是的,更改日志可以作为文件访问,此文件的路径在TeamCity构建参数中: %system.teamcity.build.changedFiles.file% 所以你可以这样做: 将命令

有没有一种简单的方法让TeamCity将文本或html更改日志作为其输出工件之一


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

可能您应该使用是的,更改日志可以作为文件访问,此文件的路径在TeamCity构建参数中:

%system.teamcity.build.changedFiles.file%
所以你可以这样做:

  • 将命令行生成步骤添加到生成中
  • 使用自定义脚本类型
  • 输入以下脚本:
复制“%system.teamcity.build.changedFiles.file%”changelog.txt
  • 最后编辑构建的工件规则,将changelog.txt包含在工件中(常规设置->工件路径->添加“changelog.txt”)

您可以通过TeamCity的REST API生成更改日志。可以找到用于此的PowerShell脚本

对于TeamCity v10.x及以上版本:

<#
.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

#将在其中创建变更日志文件
$outputFile=“%system.teamcity.build.tempDir%\releasenotesfile\%teamcity.build.id%.txt”
#teamcity服务器的url
$teamcityUrl=“%teamcity.serverUrl%”
#访问Teamcity REST API的用户名/密码
$authToken=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(“%system.teamcity.auth.userId%”):%system.teamcity.auth.password%”)
#发行说明的生成id
$buildId=%teamcity.build.id%
#获取指定更改id的提交消息
#忽略包含#忽略的消息
#忽略空行
函数GetCommitMessages($changeid)
{
$request=[System.Net.WebRequest]::Create($teamcityUrl/httpAuth/app/rest/changes/id:$changeid)
$request.Headers.Add(“授权”,“基本$authToken”);
$xml=[xml](新对象System.IO.StreamReader$request.GetResponse().GetResponseStream()).ReadToEnd()
Microsoft.PowerShell.Utility\Select Xml$Xml-XPath“/change”|
其中{($\.Node[“comment”].InnerText.Length-ne 0)-和(-Not$\.Node[“comment”].InnerText.Contains('#ignore'))}|
foreach{“+$($).Node[“user”].name):$($).Node[“comment”].InnerText.Trim().Replace(“`n”,”“)`n”}
}
#抓住所有的变化
$request=[System.Net.WebRequest]::Create($teamcityUrl/httpAuth/app/rest/changes?build=id:$($buildId)”)
$request.Headers.Add(“授权”,“基本$authToken”);
$xml=[xml](新对象System.IO.StreamReader$request.GetResponse().GetResponseStream()).ReadToEnd()
#然后获取每一个的所有提交消息
$changelog=Microsoft.PowerShell.Utility\Select Xml$Xml-XPath“/changes/change”| Foreach{GetCommitMessages($\ux.Node.id)}
$changelog>$outputFile
写入主机“保存到${outputFile}的更改日志:”
$changelog
对于Teamcity v10.x之前的版本:

<#
.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", "$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", "$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

#将在其中创建变更日志文件
$outputFile=“%system.teamcity.build.tempDir%\releasenotesfile\%teamcity.build.id%.txt”
#teamcity服务器的url
$teamcityUrl=“%teamcity.serverUrl%”
#访问Teamcity REST API的用户名/密码
$authToken=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(“%system.teamcity.auth.userId%”):%system.teamcity.auth.password%”)
#发行说明的生成id
$buildId=%teamcity.build.id%
#获取指定更改id的提交消息
#忽略包含#忽略的消息
#忽略空行
函数GetCommitMessages($changeid)
{
$request=[System.Net.WebRequest]::Create($teamcityUrl/httpAuth/app/rest/changes/id:$changeid)
$request.Headers.Add(“授权”、“$authToken”);
$xml=[xml](新对象System.IO.StreamReader$request.GetResponse().GetResponseStream()).ReadToEnd()
Microsoft.PowerShell.Utility\Select Xml$Xml-XPath“/change”|
其中{($\.Node[“comment”].InnerText.Length-ne 0)-和(-Not$\.Node[“comment”].InnerText.Contains('#ignore'))}|
foreach{“+$($).Node[“user”].name):$($).Node[“comment”].InnerText.Trim().Replace(“`n”,”“)`n”}
}
#抓住所有的变化
$request=[System.Net.WebRequest]::Create($teamcityUrl/httpAuth/app/rest/changes?build=id:$($buildId)”)
$request.Headers.Add(“授权”、“$authToken”);
$xml=[xml](新对象System.IO.StreamReader$request.GetResponse().GetResponseStream()).ReadToEnd()
#然后获取每一个的所有提交消息
$changelog=Microsoft.PowerShell.Utility\Select Xml$Xml-XPath“/changes/change”| Foreach{GetCommitMessages($\ux.Node.id)}
$changelog>$outputFile
写入主机“保存到${outputFile}的更改日志:”
$changelog

上述脚本可以工作,但是它只包含当前版本的签入注释。 所以我稍微修改了这个脚本,这样它就包含了自上次成功构建以来的所有更改。 在Teamcity中,获取最后一个成功的版本号是很困难的,因此我只获取最后10个版本,然后迭代这些更改,直到找到最后一个成功的版本

<#
.SYNOPSIS
Generates a project change log file.
.LINK
Script posted over:
http://open.bekk.no/generating-a-project-change-log-with-teamcity-and-powershell
#>

# Where the changelog file will be created
$outputFile = 
"%system.teamcity.build.tempDir%\releasenotesfile_%teamcity.build.id%.txt"
# Get the commit messages for the specified change id
# Ignore messages containing #ignore
# Ignore empty lines

# 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%
#unique id of the project
$buildType = "%system.teamcity.buildType.id%"
$changelog =""

Function GetCommitMessages($changeid)
{   
    $request = [System.Net.WebRequest]::Create("$teamcityUrl/httpAuth/app/rest/changes/id:$changeid")     
    $request.Headers.Add("AUTHORIZATION", $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 the previous 10 builds together with their changes
$request = [System.Net.WebRequest]::Create($teamcityUrl +'/httpAuth/app/rest/builds? 
locator=untilBuild:(id:'+$buildId +'),count:10,running:any,buildType: 
(id:'+$buildType+')&fields=$long,build(id,number,status,changes($long))')
$request.Headers.Add("AUTHORIZATION", $authToken);
$xml = [xml](new-object System.IO.StreamReader 
$request.GetResponse().GetResponseStream()).ReadToEnd()

# Then get all commit messages for each of them
Foreach($x in Microsoft.PowerShell.Utility\Select-Xml $xml -XPath 
"/builds/build/changes/change") 
{    
#we collect the changes until we've found the previous successfull build. so we must always collect the changes of the current build and then stop once we find a succesful build
if($x.Node.ParentNode.ParentNode.status -eq "SUCCESS" -and $x.Node.ParentNode.ParentNode.id -ne $buildId)
  { break;}
   $changelog +=GetCommitMessages($x.Node.id)  
}

$changelog > $outputFile
Write-Host "Changelog saved to ${outputFile}:"
$changelog

#将在其中创建变更日志文件
$outputFile=
%system.teamcity.build.tempDir%\releasenotesfile\U5%teamcity.build.id%.txt
#获取指定更改id的提交消息
#忽略包含#忽略的消息
#忽略空行
#teamcity服务器的url
$teamcityUrl=“%teamcity.serverUrl%”
#访问Teamcity REST API的用户名/密码
$authToken=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(“%system.teamcity.auth.userId%”):%system.teamcity.auth.password%”)
#发行说明的生成id
$buildId=%teamcity.build.id%
#项目的唯一id
$buildType=“%system.teamcity.buildType.id%”
$changelog=“”
函数GetCommitMessages($changeid)
{   
$request=[System.Net.WebRequest]::Create($teamcityUrl/httpAuth/app/rest/changes/id:$changeid)
$request.Headers.Add(“授权”、$authToken);
$xml=[xml](新对象System.IO.StreamReader$request.GetResponse().Get