Sonar.branch.name badly set for TFVC projects in TFS/VSTS

msbuild
tfs
sonarqube
branches

(Alpay Kaptaş) #1

Hello,
We were using SonarQube for our .NET projects through TFS builds until version 7.2. When I saw this new update, I migrated to this version and our builds started to fail with the following error at the Run Code Analysis phase:

02:39:05.905 ERROR: Caused by: Validation of project reactor failed:
o To use the property “sonar.branch.name”, the branch plugin is required but not installed. See the documentation of branch support: https://redirect.sonarsource.com/doc/branches.html.

It says that I need branch plugin, but there is no such plugin or at least I wasn’ t able to find it for 7.2 version of SonarQube. Where is that “sonar.branch.name” property? How can I remove it or how can I resolve this problem? I don’ t want to switch back to 7.1 version so I should get it working somehow again.

Thank you very much


(Stas Vilchik) #2

Hello,

Starting from SonarQube 7.2, the four Editions (Community, Developer, Enterprise and Data Center) are distributed separately. You can download the package edition from the “Downloads” page according to your license, unzip and install as usual. All features are already included.

As a reminder the branch support is a part of the Developer, Enterprise and Data Center editions, but not the Community one.


(Alpay Kaptaş) #3

How can i resolve this problem then? Where should i find and remove this sonar.branch.name parameter? We don’ t have any branching structure just master branch in tfs.

We were using 7.1 community edition version and we didn’ t have any problems like that. I don’ t understand what have changed in 7.2 version.

Thank you very much


(Alpay Kaptaş) #4

I found two prepare-task.js files under _tasks folder inside my TFS build agents’ work folder. I changed this part

if (defaultBranch !== currentBranch) {
    props['sonar.branch.name'] = branchName(currentBranch);

with

if (defaultBranch !== currentBranch) {
    props['sonar.branch.name1'] = branchName(currentBranch);

and everything started to work again. It looks like a problem here. Because default branch here is “refs/heads/master” but our TFS branch is coming as “$/OurTFSProjectName” so they won’ t be equal.

Would it cause any further problems to change these js files?

Thanks


(Emil) #5

I have exactly the same problem. We have two instances connected to our 7.2 internal SonarQube (Community Edition), our TFS instance has no issues and that runs 4.2.0 version of the VSTS Build Task.

Our VSTS instance has the problem that Alpay describes and that runs the 4.3.0 version of the build task.

Reading the release notes I see that 4.3.0 contains a lot of PR fixes:
https://jira.sonarsource.com/browse/VSTS/fixforversion/14393/?selectedTab=com.atlassian.jira.plugins.jira-development-integration-plugin:release-report-tabpanel

Specifically this seems like a culprit:
https://jira.sonarsource.com/browse/VSTS-156

“If the SonarQube server supports it (SQ >=7.2) then we should pass appropriate parameter on scanner side”.

I don’t work for Sonarsource and cant see the source code so this is just a guess, but seems like the 4.3.0 version of the TFS/VSTS task doesn’t account for us Community users that don’t have the branch plugin.


(Julien Henry) #6

Hi folks,

Sorry for this annoying issue that is affecting TFVC repositories. This is tracked by https://jira.sonarsource.com/browse/VSTS-161, and I will work on a fix very quickly.

Regards,


Analysis with TFS MSBuild integration is not possible anylonger after upgrading from 6.7.1 to 7.2 - branch plugin required
(Taras Galaka) #7

Thanks Alpay.

workaround confirmed, with one correction.

if (defaultBranch !== currentBranch) {

was not found in \agent_work_tasks\SonarQubePrepare_

details bellow


my configuration is:

  • TFS 2017 Update3 - 15.117.27414.0 (Tfs2017.Update3)
  • Build agent version - Agent.Version 2.122.1
  • SonarCube 7.3 Community Edition
  • TFS SonarQube Extention - Version 4.3.2
  • Git branch name - [master_2.4.5]

modified agent files
\c$\agent_work_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.3.0\common\prepare-task.js"

SonarQubeAnalyze_\4.3.0\common\prepare-task.j

line 146
currentBranch = tl.getVariable(‘Build.SourceBranch’);
//currentBranch = tl.getVariable(‘Build.SourceBranchName’);
if (defaultBranch !== currentBranch) {
props[‘sonar.branch.name1’] = branchName(currentBranch);
}

\c$\agent_work_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.3.2\common\prepare-task.js"

SonarQubePrepare_\4.3.2\common\prepare-task.jsj
line 167
if (!isDefaultBranch) {
// VSTS-165 don’t use Build.SourceBranchName
props[‘sonar.branch.name1’] = branchName(tl.getVariable(‘Build.SourceBranch’));
//props[‘sonar.branch.name’] = branchName(tl.getVariable(‘Build.SourceBranchName’));
}


Previous error message:
2018-08-30T08:34:52.7458640Z Task : Run Code Analysis
2018-08-30T08:34:52.7458640Z Description : Run scanner and upload the results to the SonarQube server.
2018-08-30T08:34:52.7458640Z Version : 4.3.0
2018-08-30T08:34:52.7458640Z Author : sonarsource

2018-08-30T08:35:05.0972310Z ERROR: Error during SonarQube Scanner execution
2018-08-30T08:35:05.0972310Z ERROR: Validation of project reactor failed:
2018-08-30T08:35:05.0972310Z o To use the property “sonar.branch.name”, the branch plugin is required but not installed. See the documentation of branch support: https://redirect.sonarsource.com/doc/branches.html.
2018-08-30T08:35:05.0972310Z ERROR:
2018-08-30T08:35:05.1441068Z ##[error]The SonarQube Scanner did not complete successfully

using sonar.branch.name=$(Build.SourceBranchName) in Prepare Analysis Configuration
did not helped

2018-08-31T09:44:25.8399476Z ERROR: Validation of project reactor failed:
2018-08-31T09:44:25.8399476Z o To use the property “sonar.branch.name”, the branch plugin is required but not installed. See the documentation of branch support: https://redirect.sonarsource.com/doc/branches.html.
2018-08-31T09:44:25.8399476Z ERROR:

your suggestion helped.
Thanks