Removing slashes from branch names in TeamCity

时间:2015-10-29 16:00:12

标签: git teamcity git-flow octopack

I am trying to pass the branch names from TeamCity to OctopusDeploy so that we can easily track which branch a deployment came from.

To do this I want to append the branch name onto the version number (or the nuget package built with octopack) so that I can display this in the OctopusDeploy UI.

This works fine, except that we are using git-flow so some of our branches contain slashes which causes octopack to fail (as file names cannot contain slashes):

+:refs/heads/(feature/*)
+:refs/heads/(release/*)
+:refs/heads/(hotfix/*)

Is there any way to replace the slashes with something else in TeamCity without changing the way we name our branches?

1 个答案:

答案 0 :(得分:4)

使用构建脚本,您可以与构建过程进行交互,并指定可以替换斜杠的自定义构建号。有关详细信息,请查看TeamCity docs

Here您可以找到有关如何更改内部版本号的c#示例。

例如,为了修改内部版本号,您可以添加CommonAssemblyInfo.cs内容,例如(从上面的链接中提取):

$ww = ([Math]::Floor([DateTime]::Now.DayOfYear/7)+1)

Write-Host "##teamcity[buildNumber '%major.minor%.$ww.%build.counter%']"
$fileLocation = Join-Path -Path "%teamcity.build.checkoutDir%" -ChildPath "\SourceDir\AssemblyInfo.cs" 

$oldValue = "AssemblyFileVersion\(""(\d+)\.\d+\.\d+\.\d+""\)"
$newValue = [string]::Concat("AssemblyFileVersion(""%major.minor%.", $ww, ".%build.counter%", """)")

(get-content $fileLocation) | foreach-object {$_ -replace $oldValue, $newValue} | set-content $fileLocation