Unable to get Sonar bitbucket plugin to work

1,787 views
Skip to first unread message

SK

unread,
May 11, 2017, 4:58:31 PM5/11/17
to SonarQube
Hello and thanks for reading my post. 

    I am trying to figure out what I'm doing wrong or what I need to do to get get this to work.  

What I want to do:

           I have a pull request, which I want Sonarqube to populate with issues in the code.  I am using the Sonar-bitbucket-plugin. There are two open pull requests.  

When i try this command it works (I think) and I get an output


But when I run using sonar-scanner, I get an error and the URL above is translated differently (as seen in the error) and it fails.

sonar-project.properties

sonar.projectKey=my:test-bb-pull-request
sonar.projectVersion=1.0
sonar.projectName=test-bb-pull-request
sonar.sources=helloworld.cpp
sonar.sourceEncoding=UTF-8

Sonar-scanner command: 

/home/support/sonar-scanner-3.0/bin/sonar-scanner \
-Dsonar.analysis.mode=issues \
-Dsonar.bitbucket.accountName=<oauth username> \
-Dsonar.bitbucket.branchName=master \
-Dsonar.host.url=http://<sonar-server IP address>\
-Dsonar.login=<sonar-user>
-Dsonar.password=Sonar123 
-Dsonar.bitbucket.oauthClientKey=<oAuth key>
-Dsonar.bitbucket.oauthClientSecret=<oAuth secret>

Error:
 
INFO: ANALYSIS SUCCESSFUL                                                                                                    
INFO: [sonar4bitbucket] Version check not possible because server.getVersion returned null                                   
INFO: Executing post-job ch.mibex.bitbucket.sonar.review.SonarReviewPostJob                                                  
INFO: ------------------------------------------------------------------------                                               
INFO: EXECUTION FAILURE                                                                                                      
INFO: ------------------------------------------------------------------------                                               
INFO: Total time: 5.020s                                                                                                     
INFO: Final Memory: 46M/211M                                                                                                 
INFO: ------------------------------------------------------------------------                                               
ERROR: Error during SonarQube Scanner execution                                                                              
com.sun.jersey.api.client.UniformInterfaceException: GET https://bitbucket.org/api/2.0/repositories/samkrishnass8/https://bit
t Found                                                                                                                      
        at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)                                                
        at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)                                             
        at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:507)                                           
        at ch.mibex.bitbucket.sonar.client.BitbucketClient.fetchPage(BitbucketClient.scala:240)                              
        at ch.mibex.bitbucket.sonar.client.BitbucketClient.ch$mibex$bitbucket$sonar$client$BitbucketClient$$fetchPullRequests
Page$1(BitbucketClient.scala:76)                                                                                             
        at ch.mibex.bitbucket.sonar.client.BitbucketClient$$anonfun$findPullRequestsWithSourceBranch$1.apply(BitbucketClient.
scala:95)                                                                                                                    
        at ch.mibex.bitbucket.sonar.client.BitbucketClient$$anonfun$findPullRequestsWithSourceBranch$1.apply(BitbucketClient.
scala:94)                                                                                                                    
        at ch.mibex.bitbucket.sonar.client.BitbucketClient.forEachResultPage(BitbucketClient.scala:251)                      
        at ch.mibex.bitbucket.sonar.client.BitbucketClient.findPullRequestsWithSourceBranch(BitbucketClient.scala:94)        
        at ch.mibex.bitbucket.sonar.review.SonarReviewPostJob.findPullRequestsForConfiguredBranch(SonarReviewPostJob.scala:37
)                                                                                                                            
        at ch.mibex.bitbucket.sonar.review.SonarReviewPostJob.executeOn(SonarReviewPostJob.scala:18)                         
        at org.sonar.scanner.phases.PostJobsExecutor.execute(PostJobsExecutor.java:63)                                       
        at org.sonar.scanner.phases.PostJobsExecutor.execute(PostJobsExecutor.java:53)                                       
        at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:82)                             
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:182)                             
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)                           
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)                                   
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:247)                                   
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:242)                        
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:232)                           
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)                           
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)                                   
        at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)                                                         
        at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)                                          
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)                           
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)                                   
        at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:115)                                 
        at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:118)                                                    
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)           
        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.$Proxy0.execute(Unknown Source)                                                                     
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)                                   
        at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)                                 
        at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)                                                       
        at org.sonarsource.scanner.cli.Main.execute(Main.java:77)                                                            
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)                                                               
ERROR:                                                                                                                       
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.                                            

SK

unread,
May 11, 2017, 4:59:56 PM5/11/17
to SonarQube
I am running Sonarqube version 6.1 

G. Ann Campbell

unread,
May 15, 2017, 1:25:02 PM5/15/17
to SonarQube
Hi,

Since you're not getting an answer here, you might want to open an issue directly on the project in GitHub.


Ann

Andrew Holland

unread,
May 15, 2017, 6:00:05 PM5/15/17
to SonarQube
it looks like your config is incorrect, this should get you going

-Dsonar.bitbucket.accountName=samkrishnass8
-Dsonar.bitbucket.repoSlug=test-sonarqube-gating

Andy

--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/3a8866c7-c97f-4a88-898a-addc0c218e31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

SK

unread,
May 16, 2017, 12:16:57 PM5/16/17
to SonarQube
Ann and Andy, thanks for the replies.  Before doing any of this, I realized that I'm not running Sonarqube over https to begin with and bitbucket authentication is not working in the first place.  A little 'duh' moment here.  Let me fix that and then work on this.  

Many thanks!
Sam

Sud Ramasamy

unread,
May 16, 2017, 2:34:27 PM5/16/17
to SonarQube
Let me know if you get this working. From what I learnt when I was trying to get this working the Sonar BitBucket plugin only works with the BitBucket server product and not the BitBucket cloud. They have different APIs.

I've started an effort to enhance the plugin to work with BitBucket Cloud. Let me know if you are interested in collaborating.

Andrew Holland

unread,
May 16, 2017, 4:36:47 PM5/16/17
to SonarQube
This plugin is only for BitBucket Cloud there is a separate version for bitbucket server.

I had this working on several repositories for our organisation account less than a month ago, we have since moved to GitHub.

Andy

SK

unread,
May 17, 2017, 1:18:53 PM5/17/17
to SonarQube
Hi Andrew

   Before I go off trying to serve sonarqube over https, does the plugin care if its only internal or to the world?  should my https served sonarqube be accessible to the world?  

thanks
Sam

Andrew Holland

unread,
May 18, 2017, 4:10:02 AM5/18/17
to SonarQube
Sam

We run our SonarQube instance on AWS and only allow access from specific IP address’s, the only ip we allow is bitbucket but that is for web hook notifications.

Andy


SK

unread,
May 18, 2017, 2:20:19 PM5/18/17
to SonarQube
Got it. Thanks!  :) 

SK

unread,
May 22, 2017, 1:48:51 PM5/22/17
to SonarQube
Hi

  I got it working using sonarqube over http and bitbucket cloud.  It was an unnecessary waste of time tying to make sonarqube serve over https afterall.  That was a "witch-hunt" afterall.  :) 

Andrew was right on the money in one of his previous posts.  the repo slug does not have to be a complete URL but only a part of the URL that will actually fetch something. 

First create a oAuth in bitbucket - Give the consumer almost all the privileges to the repo.  You can withhold Admin/Delete privileges, but give it everything else if possible.  There might be finer tuning to the permissions, but I don't have the patience to test all of them.  :) 

sonar analysis parameters for Jenkins

          
sonar.bitbucket.repoSlug=<name of bitbucket repo >        

sonar.bitbucket.accountName=< bitbucket account name >
sonar.bitbucket.oauthClientKey=<oauth client key>
sonar.bitbucket.oauthClientSecret=<secret>

sonar.projectKey=<sonar project>      -----> Does not need to exist.  Looks like it automatically chooses the default rules set in sonarqube.  
sonar.sources=.

sonar.login=<sonar login>
sonar.password=<sonar passwd>

sonar.bitbucket.branchName=${GIT_BRANCH} --> This property added as a command line argument in jenkins build

sonar.host.url=<sonar server url>
sonar.analysis.mode=issues/preview  ---> could not find out the difference between these two. both behave the same. 

Proof that it works in bitbucket. :)  

G. Ann Campbell

unread,
May 23, 2017, 8:28:41 AM5/23/17
to SonarQube
Hi,

Thanks for coming back to us to verify success. Posterity will thank you!


Ann

SK

unread,
May 23, 2017, 1:18:41 PM5/23/17
to SonarQube
You're most welcome. Thanks for an excellent product Sonarqube!  

Sud Ramasamy

unread,
May 24, 2017, 3:08:32 PM5/24/17
to SonarQube
You are right. I didn't realize we were talking about a different plugin and not https://github.com/AmadeusITGroup/sonar-stash.

Thanks to this thread we've successfully integrated SonarQube/Sonar scanning into our PRs on BitBucket Cloud repos. 
Reply all
Reply to author
Forward
0 new messages