.Net application builds and versions using bamboo

I have a .net project that i am already using MSbuild for and i have that working great. My question is i would like to be able to save each version and actually version my application on each build using bamboo. Then we have a dev/test/prod server that i would like to be able to push any version to any server at anytime.. now i see references for these sort of things but i cant seem to find any good information on how to make this all happen. Can someone point me in a direction for this?

Thanks!

1 answer

We used to do this with CruiseControl.net but decided not to with bamboo.

It is an old powershell script but it worked fine. You'd need to pass in the parameters from Bamboo as arguments to the script or use them inline in the new script command running as powershell.

function SetVersion ($file)
{
	$version = $ENV:CCNetLabel
	$svn_rev = ([int] $version.Split('.')[3])
	$mod_svn_rev = $svn_rev % 10000
	$version = $version.Replace("$svn_rev","$mod_svn_rev")
	
	$fileObject = get-item $file
	$fileObject.Set_IsReadOnly($False)

	"Changing version in $file to $version"

	$sr = new-object System.IO.StreamReader( $file, [System.Text.Encoding]::GetEncoding("utf-8") ) 
	$content = $sr.ReadToEnd()
	$sr.Close()

	$content = [Regex]::Replace($content, "(\d+)\.(\d+)\.(\d+)\.(\d+)", $version);

	$sw = new-object System.IO.StreamWriter( $file, $false, [System.Text.Encoding]::GetEncoding("utf-8") )
	$sw.Write( $content )
	$sw.Close()
	$fileObject.Set_IsReadOnly($True)
}

# Set the Assembly version
$info_files = Get-ChildItem .\ -Recurse -Include "AssemblyInfo.cs" | where {$_ -notmatch 'A3Domain'}
foreach($file in $info_files)
{
	Setversion $file		
}

Our labels ($ENV:CCNetLabel) were already a 3 piece release version then we tacked on a piece of the revision. Mod by 10000 was a quick hack to avoid unsigned __int16 overflow, it can produce non sequential versions though so I'd try to avoid it.

Basically the idea is to change the AssemblyInfo.cs BEFORE the build.

I used this as a template with minor modifications and it works fine.

My only complaint is that it has to be checked into the repo to work, it would be nice to have it as a task type

I replaced your code at the top up to the point where your version is modified with this

param([string]$versionNew)
 
function SetVersion ($file, $version)

changed your calling line to this

Setversion $file $versionNew

 And then created a script task in bamboo, setting Run as Powershell script with this as the body

.\ChangeAssemblyInfo.ps1 -version 0.1.${bamboo.buildNumber}.0

Correction:

you can put the whole script into the bamboo task, but that hurt my sensibilities.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,561 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you