Decorate BitBucket Cloud PRs with SonarCloud and Jenkins

bitbucket

(Schnatterer) #1

I’d like to continue this little Twitter Thread with @Fabrice_Bellingard here :slight_smile:

Our situation is as follows: We’re about to start using SonarCloud for SCM-Manager and would like to decorate our PRs at BitBucket using our Jenkins instance.

I’ve read the docs for Integration with Bitbucket Cloud - with refers to integration with BitBucket Pipelines. Difficult to transfer to Jenkins.

Also, the docs state that

Pull request decoration with inline comments to show the issues within the PR

So I read the docs for Pull Request analysis, which refers to GitHub and vsts, but not BitBucket.

So what I’m looking for are the sonar.* Parameters that I need to set when analysing a PR from Jenkins (using Maven). On twitter, Fabrice said

Looks like we haven’t documented them yet.

BTW - We already implemented a Jenkins Shared Library (cloudogu/ces-build-lib) that implements PR decoration for SonarQube and the GitHub plugin. While we’re at it, we would like to extend it for BitBucket or the new SonarCloud integration without GitHub plugin.


(Nicolas Bontoux) #2

Apologies for that. As you might have noticed this revamped forum is quite recent, and we tend to stick with default settings to then monitor feedback and adjust/override where really needed. Agreed that 2 is a bit harsh, increased to 6 for now (you should be able to edit your post).


(Schnatterer) #3

Thanks, I edited my post.
I got a lot of “Sorry, an error has occurred.” messages, which made this process a bit cumbersome. I wasn’t able to add this link: SonarQube and the GitHub plugin - because saving lead to “Sorry, an error has occurred.”


(Fabrice Bellingard) #4

Here are the parameters that you need to pass when you want to do PR analysis on Bitbucket Cloud:

sonar.pullrequest.base=master
sonar.pullrequest.branch=feature/my-new-feature
sonar.pullrequest.key=5
sonar.pullrequest.provider=bitbucketcloud
sonar.pullrequest.bitbucketcloud.owner=bellingard
sonar.pullrequest.bitbucketcloud.repository=my-repo

Please tell me if it doesn’t work.


Pull Request decoration (Bitbucket Cloud)
(Schnatterer) #5

Thanks for your swift response, @Fabrice_Bellingard.

I set up a test repo and managed to analyse a regular branch into sonarcloud.

However, PR analysis failed.

Actual call by Jenkins

./mvnw --batch-mode -V -U -e -Dsurefire.useFile=false sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=****** -X -Dsonar.pullrequest.base=default -Dsonar.pullrequest.branch=branchWithMoreSQIssues -Dsonar.pullrequest.key=1 -Dsonar.pullrequest.provider=bitbucketcloud -Dsonar.pullrequest.bitbucketcloud.owner=schnatterer

Hopefully the relevant part of the log:

[DEBUG] 18:24:00.474 GET 200 https://sonarcloud.io/api/project_pull_requests/list?project=info.schnatterer.samples%3Aspring-petclinic-bb | time=11ms
[INFO] 18:24:00.476 Load project pull requests (done) | time=13ms
[INFO] 18:24:00.476 Load branch configuration
[DEBUG] 18:24:00.477 Not on a Bitbucket pipeline.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.196 s
[INFO] Finished at: 2018-07-10T18:24:00+02:00
[INFO] Final Memory: 44M/753M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.1.1168:sonar (default-cli) on project spring-petclinic-bb: Unable to load component class org.sonar.scanner.scan.ProjectLock: Unable to load component class org.sonar.scanner.scan.DefaultInputModuleHierarchy: Unable to load component class org.sonar.scanner.scan.ProjectBuildersExecutor: Unable to load component class org.sonar.plugins.github.PullRequestProjectBuilder: Unable to load component class org.sonar.plugins.github.GitHubPluginConfiguration: Unable to load component class org.sonar.scanner.scan.MutableProjectSettings: Unable to load component class org.sonar.scanner.repository.ProjectRepositories: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration: Pull request with branch does not exist on server: default -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.1.1168:sonar (default-cli) on project spring-petclinic-bb: Unable to load component class org.sonar.scanner.scan.ProjectLock
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
	at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
	at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:50)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to load component class org.sonar.scanner.scan.ProjectLock
	at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:67)
	at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:104)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	... 27 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
	at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:281)
	at org.sonar.scanner.scan.ProjectScanContainer.doBeforeStart(ProjectScanContainer.java:118)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:134)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:82)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:131)
	at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy23.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
	at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:65)
	... 30 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.DefaultInputModuleHierarchy
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
	... 52 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectBuildersExecutor
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.SingleMemberInjector.getMemberArguments(SingleMemberInjector.java:61)
	at org.picocontainer.injectors.MethodInjector.getMemberArguments(MethodInjector.java:100)
	at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:112)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
	at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
	at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
	at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
	... 66 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.plugins.github.PullRequestProjectBuilder
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:621)
	at org.picocontainer.parameters.CollectionComponentParameter.getArrayInstance(CollectionComponentParameter.java:334)
	at org.picocontainer.parameters.CollectionComponentParameter.access$100(CollectionComponentParameter.java:49)
	at org.picocontainer.parameters.CollectionComponentParameter$1.resolveInstance(CollectionComponentParameter.java:139)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:141)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
	... 81 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.plugins.github.GitHubPluginConfiguration
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
	... 97 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.MutableProjectSettings
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
	... 111 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.repository.ProjectRepositories
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
	... 125 more
Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
	at org.picocontainer.injectors.SingleMemberInjector.getMemberArguments(SingleMemberInjector.java:61)
	at org.picocontainer.injectors.MethodInjector.getMemberArguments(MethodInjector.java:100)
	at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:112)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
	at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
	at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
	at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
	... 139 more
Caused by: Pull request with branch does not exist on server: default

Any ideas?
The Jenkins I use is behind authentication, but I will gladly provide you with more log output, if necessary.


VSTS + SonarCloud (paid version) Unable to load component / Project was never analyzed / Failed to load profiles
(Fabrice Bellingard) #6

Yes, I know where the problem comes from :slight_smile:

For some reason, your default branch on Git is called “default” and not “master”. So when the analysis is triggered with -Dsonar.pullrequest.base=default, SonarCloud says that this base branch is unknown. To fix this, go on the “Administration > Branches and Pull Requests” admin page of your project, and change the name of the default branch from “master” to “default” (using the gear icon on the right).

Out of curiosity: any reason why your default branch is not called “master” on your Git repo?


(Schnatterer) #7

It’s a mercurial repo. In mercurial, “default” is the equivalent of Git’s master.

Can I get SonarCloud to decorate PRs on Mercurial?

Renaming is not an option. I’m planning on using this for scm-manager, which has been on Mercurial for ages.


(Fabrice Bellingard) #8

I’m not telling you that you need to rename your branch in Mercurial, but to rename the default branch in SonarCloud from “master” to “default”:

(this won’t update anything on your Mercurial repository, this is just a setting on SonarCloud side)


(Schnatterer) #9

Aah - rename in Sonar - of course :slight_smile:
That did it, thanks!
I now have a Analysis Result in SonarCloud.

However, the PR is not annotated. It should be possible to make SonarCloud comment on PRs like for GitHub, right?

I installed the BitBucket SonarCloud addon.
Anything else I have to do?

PS @NicoB My first try to answer lead to my post being flagged as spam. Why?


Sonarqube Build Failure with Error - Unable to load component class org.sonar.scanner.scan.ProjectLock
(Nicolas Bontoux) #10

Got a notification indeed. Alert based on the number of outbound links. Gave us the opportunity to whitelist a number of hosts that shouldn’t be considered, so this shouldn’t happen any longer (whitelisted things like sonarcloud, github etc.).

Quick note on this:

Note that by default the forum warns when a link was already shared, however it should be possible to close the warning message and proceed nonetheless.

Again, apologies for the few hiccups, we’re adjusting all this and are committed to make this a smooth experience.


(Fabrice Bellingard) #11

Have you linked your repository to the relevant project on SonarCloud? (in the “SonarCloud Settings” page in Bitbucket)


(Schnatterer) #12

I did, but I might have chosen the wrong one. I analysed the same project from Github (where a PR was commented on successfully by SonarCloud). I used a different key, but the displayed name was the same, which made it difficult to distinguish on BitBucket:

Is it possible to rename projects in sonarcloud, keeping the key?

Anyways, I deleted the GitHub one for now, double-checked I chose the correct project in BitBucket (I can see the widget, pointing to the correct project on SonarCloud here) and ran the build again.
I even created a new PR.

Still no comments on the PR, though.

Here’s the log of the Sonar Stage on Jenkins, in case that helps:

 ./mvnw --batch-mode -V -U -e -Dsurefire.useFile=false sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=****** -Dsonar.pullrequest.base=default -Dsonar.pullrequest.branch=branchWithMoreSQIssues -Dsonar.pullrequest.key=2 -Dsonar.pullrequest.provider=bitbucketcloud -Dsonar.pullrequest.bitbucketcloud.owner=schnatterer -Dsonar.pullrequest.bitbucketcloud.repository=sonarcloudtest
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:37+02:00)
Maven home: /home/jenkins/.m2/wrapper/dists/apache-maven-3.3.3-bin/3opbjp6rgl6qp7k2a6tljcpvgp/apache-maven-3.3.3
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-127-generic", arch: "amd64", family: "unix"
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 KB at 45.4 KB/sec)
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 KB at 30.2 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/mojo/sonar-maven-plugin/maven-metadata.xml
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/mojo/sonar-maven-plugin/maven-metadata.xml (1014 B at 47.2 KB/sec)
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building petclinic 1.5.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- sonar-maven-plugin:3.4.1.1168:sonar (default-cli) @ spring-petclinic-bb ---
[INFO] User cache: /home/jenkins/.sonar/cache
[INFO] SonarQube version: 7.3.0
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[INFO] Publish mode
[INFO] Load global settings
[INFO] Load global settings (done) | time=159ms
[INFO] Server id: AWHW8ct9-T_TB3XqouNu
[INFO] User cache: /home/jenkins/.sonar/cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=62ms
[INFO] Load/download plugins (done) | time=128ms
[INFO] Loaded core extensions: branch-scanner
[INFO] Process project properties
[INFO] Load project branches
[INFO] Load project branches (done) | time=17ms
[INFO] Load project pull requests
[INFO] Load project pull requests (done) | time=15ms
[INFO] Load branch configuration
[INFO] Load branch configuration (done) | time=4ms
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=77ms
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=0ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=34ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=697ms
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=26ms
[INFO] Project key: info.schnatterer.samples:spring-petclinic-bb
[INFO] Project base dir: /home/jenkins/workspace/example-multibranch_PR-2-L6N4RKT74EPZWQ5M6YQ44WED6ASGWM73FBC2KKLXWOBC6EI6AGCQ
[INFO] Organization key: schnatterer-github
[INFO] Pull request 2 for merge into default from branchWithMoreSQIssues
[INFO] -------------  Scan petclinic
[INFO] Base dir: /home/jenkins/workspace/example-multibranch_PR-2-L6N4RKT74EPZWQ5M6YQ44WED6ASGWM73FBC2KKLXWOBC6EI6AGCQ
[INFO] Working dir: /home/jenkins/workspace/example-multibranch_PR-2-L6N4RKT74EPZWQ5M6YQ44WED6ASGWM73FBC2KKLXWOBC6EI6AGCQ/target/sonar
[INFO] Source paths: pom.xml, src/main/java
[INFO] Test paths: src/test/java
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] SCM collecting changed files in the branch
[INFO] SCM collecting changed files in the branch (done) | time=0ms
[INFO] Load server rules
[INFO] Load server rules (done) | time=93ms
[INFO] Index files
[INFO] 38 files indexed
[INFO] Quality profile for java: Sonar way
[INFO] Quality profile for xml: Sonar way
[INFO] Sensor JavaSquidSensor [java]
[INFO] Configured Java source version (sonar.java.source): 8
[INFO] JavaClasspath initialization
[INFO] JavaClasspath initialization (done) | time=9ms
[INFO] JavaTestClasspath initialization
[INFO] JavaTestClasspath initialization (done) | time=3ms
[INFO] Java Main Files AST scan
[INFO] 25 source files to be analyzed
[INFO] 25/25 source files have been analyzed
[INFO] Java Main Files AST scan (done) | time=1655ms
[INFO] Java Test Files AST scan
[INFO] 12 source files to be analyzed
[INFO] 12/12 source files have been analyzed
[INFO] Java Test Files AST scan (done) | time=598ms
[INFO] Sensor JavaSquidSensor [java] (done) | time=2642ms
[INFO] Sensor SurefireSensor [java]
[INFO] parsing [/home/jenkins/workspace/example-multibranch_PR-2-L6N4RKT74EPZWQ5M6YQ44WED6ASGWM73FBC2KKLXWOBC6EI6AGCQ/target/surefire-reports]
[INFO] Sensor SurefireSensor [java] (done) | time=85ms
[INFO] Sensor JaCoCoSensor [java]
[INFO] Analysing /home/jenkins/workspace/example-multibranch_PR-2-L6N4RKT74EPZWQ5M6YQ44WED6ASGWM73FBC2KKLXWOBC6EI6AGCQ/target/jacoco.exec
[INFO] Analysing /home/jenkins/workspace/example-multibranch_PR-2-L6N4RKT74EPZWQ5M6YQ44WED6ASGWM73FBC2KKLXWOBC6EI6AGCQ/target/jacoco-it.exec
[INFO] Analysing /home/jenkins/workspace/example-multibranch_PR-2-L6N4RKT74EPZWQ5M6YQ44WED6ASGWM73FBC2KKLXWOBC6EI6AGCQ/target/sonar/jacoco-merged.exec
[INFO] No information about coverage per test.
[INFO] Sensor JaCoCoSensor [java] (done) | time=103ms
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] 1 source files to be analyzed
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=354ms
[INFO] 1/1 source files have been analyzed
[INFO] Sensor XML Sensor [xml]
[INFO] Sensor XML Sensor [xml] (done) | time=91ms
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=12ms
[INFO] Sensor JavaSecuritySensor [security]
[INFO] Analyzing 83 ucfgs to detect vulnerabilities.
[INFO] Sensor JavaSecuritySensor [security] (done) | time=101ms
[INFO] Sensor CSharpSecuritySensor [security]
[INFO] Analyzing 0 ucfgs to detect vulnerabilities.
[INFO] Sensor CSharpSecuritySensor [security] (done) | time=9ms
[INFO] Sensor Java CPD Block Indexer
[INFO] Sensor Java CPD Block Indexer (done) | time=47ms
[INFO] SCM provider for this project is: hg
[INFO] 1 files to be analyzed
[INFO] 1/1 files analyzed
[INFO] Skipping CPD calculation for short living branch and pull request
[INFO] Analysis report generated in 87ms, dir size=64 KB
[INFO] Analysis reports compressed in 8ms, zip size=22 KB
[INFO] Analysis report uploaded in 113ms
[INFO] ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/project/issues?id=info.schnatterer.samples%3Aspring-petclinic-bb&pullRequest=2&resolved=false
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at https://sonarcloud.io/api/ce/task?id=AWSKER18r5pnsk0fp3d4
[INFO] Task total time: 7.473 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.314 s
[INFO] Finished at: 2018-07-11T17:58:54+02:00
[INFO] Final Memory: 55M/957M
[INFO] ------------------------------------------------------------------------

(Fabrice Bellingard) #14

When I look at your PR on Bitbucket Cloud, I can see that the “decoration” is available:

Maybe you were expecting comments inside the PR itself? (like what we are doing on GitHub) This is not yet available.


(Schnatterer) #15

It’s good to know what to look for.

BitBucket seems to be A/B testing a new UI. This is how BitBucket looks in my Firefox 61.01 (logged in at BitBucket). Can’t find Code Quality there:

When I click “temporarily disable new UI” it looks pretty much like your screenshot, only with an empty Code Quality section.

Now, I tested the same page in Chrome 67.0.3396.99 and Firefox 62.0b6. Both show the Code Quality just like in your screenshot. Thanks for pointing me towards the right direction!

There seem to be some browser / BitBucket related display issues with the SonarCloud integration.


(Fabrice Bellingard) #18

Are you using an ad blocker? As mentioned in the documentation, this is a known problem on Bitbucket Cloud when you are using third-party integrations that contribute elements to the UI.


(Schnatterer) #19

I can confirm that for the “old” BitBucket UI, disabling the adblock resolves the issue, thanks.

Still no “Code Quality” section in the new UI. I will use the feedback button to let them know :slight_smile:


(Fabrice Bellingard) #20

:+1: This new UI is still an experimentation, so it’s definitely a good idea that users bring those problems to them. Thanks!


(Schnatterer) #21

Just some last words on this topic - if anyone is interested in our working solution for analysing Mercurial BitBucket projects with Jenkins and SonarCloud, have a look at the Jenkinsfile of SCM-Manager.

In future, we’ll might add Mercurial and BitBucket support to our Jenkins shared library ces-build-lib (tracked by this issue), providing a solution that can easily be reused by other pipelines.

BTW, we already implemented support for GitHub. You can analyze your projects from Jenkins Pipelines as easy as this:

  def sonarQube = SonarCloud(this, [sonarQubeEnv: 'sonarcloud.io', sonarOrganization: 'YOUR_ID'])

  sonarQube.analyzeWith(new MavenInDocker(this, "3.5.0-jdk-8"))

  if (!sonarQube.waitForQualityGateWebhookToBeCalled()) {
    currentBuild.result ='UNSTABLE'
  }

See the docs for more info.