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?
Using a build script you can interact with the build process and specify a custom build number where you can replace the slashes. For more details you can check the TeamCity docs.
Here you can find an c# example on how to alter the build number.
By example, in order to mangle the build number you can add CommonAssemblyInfo.cs
with a content like (extracted from the above link):
$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