The scanner keeps analyzing only one file until memory exceeded on Bitbucket pipeline

Hi there
I’m configuring Sonar PR analysis for my Bitbucket Repository. The pipeline works but when the scanner analyze my first file, the analysis was looping until memory exceeded and the pipeline failed.

This is my bitbucket-pipelines.yml file

image: node:12.20

    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
    - step: &analyze-on-sonarcloud
        name: Build, test and analyze on SonarCloud
          - node
          - sonar
          - pipe: sonarsource/sonarcloud-scan:1.4.0
              SONAR_SCANNER_OPTS: -Xmx512m
              SONAR_TOKEN: ${SONAR_TOKEN}
              DEBUG: 'true'
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.6
              SONAR_TOKEN: ${SONAR_TOKEN}
      - step: *analyze-on-sonarcloud

Please help me resolve the issue.
Thanks so much

Hey there

A few things to try:

  • Try bumping the image node:12.20 to node:12.22 (this is the minimum supported version of NodeJS for running analysis)
  • You should also try bumping up the memory granted to the Docker image and scanner java process, such as this user did (check their bitbucket-pipelines.yml file for how they bump the memory allocated to Docker)

Thanks so much Colin.
I tried follow your solution.
Now I am facing this prolem

Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(
	at org.picocontainer.DefaultPicoContainer.getComponent(
	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(
	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(
	at org.picocontainer.injectors.SingleMemberInjector.getParameter(
	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(
	at org.picocontainer.injectors.ConstructorInjector$
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(
	at org.picocontainer.behaviors.Stored.getComponentInstance(
	at org.picocontainer.DefaultPicoContainer.getInstance(
	at org.picocontainer.DefaultPicoContainer.getComponent(
	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(
	... 34 more
Caused by: Parameter 'sonar.pullrequest.key' is mandatory for a pull request analysis
07:30:43.019 ERROR: 
07:30:43.019 ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

This is my file


I removed the line sonar.pullrequest.base=develop to make the scanner automatically detect PR parameters from Bitbucket.
Now the scanner run but, I’m still facing main problem. I will try to increase more memory as your sugestion

I understand that Bitbucket only allow total 4096MB for a pipeline. If docker service has 4096MB memory, steps won’t have enough memory to run
Screen Shot 2022-06-02 at 15.09.02

Hurray, finally I make it done.
I set docker memory to 2048MB and SONAR_SCANNER_OPTS for the pipe to 2048MB too.
Then I turned off Sonar debug by removing SONAR_DEBUG variables because I think the debuggers also need memory
Next, I tried to reduce the number of files that are analyzed by adding more file extensions to option “sonar.exclusions”, such as **/*.spec.ts (test files)
Finally, the scanner works properly

However, Can you tell me why the scanner needs so much memory? Our project only has about 300 files now.
Thanks you so much @Colin