Automatically populate your Source branch when publishing to Sonar

10 May, 2016
Xebia Background Header Wave
When you enable your build definition to trigger on multiple branches, you may not want them all to publish into the same Sonar project. 
Sonar has the concept of Branches, they’re simply appended to the Project Key with a `-`. This prevents an old Hotfix build from messing up the trend information of your current development. It also helps you configure different baselines for older versions (branches).
When building from the Visual Studio Team Services Build tasks you can configure the branch automatically by including the Build.SourceBranchName variable in your Project Key:

Some background on the values assigned to this variable can be found on the Visual Studio Team Build Variables documention:

The name of the branch the build was queued for.
  • For Git this is the last path segment in the ref. For example inrefs/heads/masterthe name ismaster.
  • For TFVC this will last path segment in the root server path for the workspace. For example in $/teamproject/branch the name is branch
Jesse Houwing
Jesse is a passionate trainer and coach, helping teams improve their productivity and quality all while trying to keep work fun. He is a Professional Scrum Trainer (PST) through, Microsoft Certified Trainer and GitHub Accredited Trainer. Jesse regularly blogs and you'll find him on StackOverflow, he has received the Microsoft Community Contributor Award three years in a row and has been awarded the Microsoft Most Valuable Professional award since 2015. He loves espresso and dark chocolate, travels a lot and takes photos everywhere he goes.

Get in touch with us to learn more about the subject and related solutions

Explore related posts