10

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?

Richard Dalton
  • 35,513
  • 6
  • 73
  • 91

1 Answers1

4

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
Community
  • 1
  • 1
dan
  • 13,132
  • 3
  • 38
  • 49
  • Thanks, that helped. If you add some of the example code (I ended up using powershell, but anything is fine) to your answer so it doesn't depend on external resources then I'll award the bounty to you. – Richard Dalton Nov 09 '15 at 08:34