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

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  step:
    - step: &analyze-on-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - node
          - sonar
        script:
          - pipe: sonarsource/sonarcloud-scan:1.4.0
            variables:
              SONAR_SCANNER_OPTS: -Xmx512m
              SONAR_TOKEN: ${SONAR_TOKEN}
              DEBUG: 'true'
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.6
            variables:
              SONAR_TOKEN: ${SONAR_TOKEN}
pipelines:
  pull-requests:
    '**':
      - 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(ComponentContainer.java:52)
	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:50)
	... 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 sonar-project.properties file

sonar.projectKey=bein-platform_bein-backend
sonar.organization=bein
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.exclusions=**/*.js
sonar.test.exclusions=**/*.spec.ts,**/*.mock.ts
sonar.pullrequest.base=develop

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