Automatically setting sonar.branch in Jenkins Declarative Pipeline msbuilds

1,794 views
Skip to first unread message

chri...@gmail.com

unread,
Apr 19, 2017, 5:50:45 AM4/19/17
to SonarQube
Our Tools:
- Bitbucket Server (formely known as Stash) with Sonar for Bitbucket plugin
- Jenkins CI (LTS) with Sonar plugin

I have a Jenkinsfile using the declarative pipeline that looks something like this:

withEnv([
   
"msbuild15=${tool name: 'Visual Studio 2017', type: 'msbuild'}",
   
"vstest15=${tool name: 'VSTest 2017', type: 'org.jenkinsci.plugins.vstest_runner.VsTestInstallation'}",
   
"sonarQubeMsbuildHome=${tool 'SonarQube MSBuild'}"
]) {
    withSonarQubeEnv
('v-sonarqube') {
        bat
"$sonarQubeMsbuildHome\\SonarQube.Scanner.MSBuild.exe begin /k:proj001"
        bat
"nuget.exe restore"
        bat
"\"$msbuild15\"" +
           
" \"Project001.sln\"" +
           
" /p:DeployOnBuild=true;PublishProfile=DeployPackage;Configuration=Release /m /nr:false"
        bat
(returnStatus: true,
            script
: "\"$vstest15\"" +
               
" Project001.Web.Tests/bin/Release/net45/Project001.Web.Tests.dll" +
               
" Project001.Common.Tests/bin/Release/net45/Project001.Common.Tests.dll" +
               
" /UseVsixExtensions:false /Logger:trx /Parallel"
       
);
        bat
"$sonarQubeMsbuildHome\\SonarQube.Scanner.MSBuild.exe end"
   
}
}

We then have Jenkins/Bitbucket setup to build our pull requests automatically.

Our issue we believe is that sonar.branch property is not being set (I would have assumed 'withSonarQubeEnv' would have set this automatically), so that all pull request builds are ending up in the same project (ie: in proj001 instead of proj001:branch-name)

How can we resolve this issue?

Kind regards,
Chris Stylianou

Julien HENRY

unread,
Apr 19, 2017, 8:14:18 AM4/19/17
to SonarQube, chri...@gmail.com
Hi Chris,

Pull requests should not be analyzed as a branch and results should not be published to the SonarQube server. Instead you should use a preview analysis mode + use the sonar-bitbucket-plugin to report issues on the pull request:

Using sonar.branch should be reserved to analyze long living branches of your project (for example maintenance branches).

++

Julien

chri...@gmail.com

unread,
Apr 19, 2017, 8:50:45 AM4/19/17
to SonarQube, chri...@gmail.com
Hi Julien, thanks for your swift reply.

I am now confused, as we have used the instructions from "Sonar for Bitbucket Server" plugin (https://marketplace.atlassian.com/plugins/ch.mibex.stash.sonar4stash/server/overview)

We are using on-premise Bitbucket Server (Stash), not the Bitbucket Cloud.

What should we do?

Kind regards,
Chris Stylianou

Fabrice Bellingard

unread,
Apr 25, 2017, 3:17:22 AM4/25/17
to chri...@gmail.com, SonarQube
On Wed, Apr 19, 2017 at 2:50 PM, <chri...@gmail.com> wrote:
Hi Julien, thanks for your swift reply.

I am now confused, as we have used the instructions from "Sonar for Bitbucket Server" plugin (https://marketplace.atlassian.com/plugins/ch.mibex.stash.sonar4stash/server/overview)

We are using on-premise Bitbucket Server (Stash), not the Bitbucket Cloud.

What should we do?

Hi Chris,

you should send a support request to the company which sells this BitBucket extension. Unfortunately, neither SonarSource nor the community can help you on this.

Hope you'll find your way,

Best regards,
Fabrice BELLINGARD | SonarSource
SonarQube & SonarLint Product Manager
http://sonarsource.com


 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/36cc6dd8-17d2-4e21-ba4e-602d99c9623e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dan Tran

unread,
Apr 25, 2017, 5:00:35 PM4/25/17
to SonarQube, chri...@gmail.com
Take a look at  BitBucket Branch Source plugin, it creates BRANCH_NAME env for you to pass into your -Dsonar.branch.

How many branches do you have?

-Dan 

Chris Stylianou

unread,
Apr 25, 2017, 5:34:06 PM4/25/17
to Dan Tran, SonarQube
Hi Dan,

We have a master branch and the. Use feature branches with pull requests back into the master branch. We are using Jenkins declarative pipelines. 

Kind regards,
Chris Stylianou
Reply all
Reply to author
Forward
0 new messages