Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing slashes from branch names in TeamCity

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?

like image 777
Richard Dalton Avatar asked Oct 29 '15 16:10

Richard Dalton


1 Answers

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
like image 100
dan Avatar answered Oct 16 '22 04:10

dan